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 | |
Ted Kremenek | 3632a35 | 2009-01-28 20:46:26 +0000 | [diff] [blame] | 17 | #include <utility> |
Chris Lattner | ae50fa0 | 2009-03-05 00:00:31 +0000 | [diff] [blame] | 18 | #include <cassert> |
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; |
Chris Lattner | ae50fa0 | 2009-03-05 00:00:31 +0000 | [diff] [blame] | 22 | class raw_ostream; |
Benjamin Kramer | ceafc4b | 2010-03-16 14:48:07 +0000 | [diff] [blame] | 23 | class StringRef; |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 24 | template <typename T> struct DenseMapInfo; |
Chris Lattner | 06159e8 | 2009-12-15 07:26:51 +0000 | [diff] [blame] | 25 | template <typename T> struct isPodLike; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 28 | namespace clang { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 29 | |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 30 | class SourceManager; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 31 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 32 | /// FileID - This is an opaque identifier used by SourceManager which refers to |
| 33 | /// a source file (MemoryBuffer) along with its #include path and #line data. |
| 34 | /// |
| 35 | class FileID { |
| 36 | /// ID - Opaque identifier, 0 is "invalid". |
| 37 | unsigned ID; |
| 38 | public: |
| 39 | FileID() : ID(0) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 41 | bool isInvalid() const { return ID == 0; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 43 | bool operator==(const FileID &RHS) const { return ID == RHS.ID; } |
| 44 | bool operator<(const FileID &RHS) const { return ID < RHS.ID; } |
| 45 | bool operator<=(const FileID &RHS) const { return ID <= RHS.ID; } |
| 46 | bool operator!=(const FileID &RHS) const { return !(*this == RHS); } |
| 47 | bool operator>(const FileID &RHS) const { return RHS < *this; } |
| 48 | bool operator>=(const FileID &RHS) const { return RHS <= *this; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 49 | |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 50 | static FileID getSentinel() { return get(~0U); } |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 51 | unsigned getHashValue() const { return ID; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 52 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 53 | private: |
| 54 | friend class SourceManager; |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 55 | static FileID get(unsigned V) { |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 56 | FileID F; |
| 57 | F.ID = V; |
| 58 | return F; |
| 59 | } |
| 60 | unsigned getOpaqueValue() const { return ID; } |
| 61 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | |
| 63 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 64 | /// SourceLocation - This is a carefully crafted 32-bit identifier that encodes |
| 65 | /// a full include stack, line and column number information for a position in |
| 66 | /// an input translation unit. |
| 67 | class SourceLocation { |
| 68 | unsigned ID; |
Chris Lattner | bcc2a67 | 2009-01-19 06:46:35 +0000 | [diff] [blame] | 69 | friend class SourceManager; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 70 | enum { |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 71 | MacroIDBit = 1U << 31 |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 72 | }; |
Chris Lattner | 9ebac5e | 2009-01-19 06:57:37 +0000 | [diff] [blame] | 73 | public: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 74 | |
| 75 | SourceLocation() : ID(0) {} // 0 is an invalid FileID. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 76 | |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 77 | bool isFileID() const { return (ID & MacroIDBit) == 0; } |
| 78 | bool isMacroID() const { return (ID & MacroIDBit) != 0; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 80 | /// isValid - Return true if this is a valid SourceLocation object. Invalid |
| 81 | /// SourceLocations are often used when events have no corresponding location |
| 82 | /// in the source (e.g. a diagnostic is required for a command line option). |
| 83 | /// |
| 84 | bool isValid() const { return ID != 0; } |
| 85 | bool isInvalid() const { return ID == 0; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 6fda54c | 2009-01-19 07:00:35 +0000 | [diff] [blame] | 87 | private: |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 88 | /// getOffset - Return the index for SourceManager's SLocEntryTable table, |
| 89 | /// note that this is not an index *into* it though. |
| 90 | unsigned getOffset() const { |
| 91 | return ID & ~MacroIDBit; |
Chris Lattner | 4d10ef1 | 2009-01-19 06:55:08 +0000 | [diff] [blame] | 92 | } |
Chris Lattner | 6fda54c | 2009-01-19 07:00:35 +0000 | [diff] [blame] | 93 | |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 94 | static SourceLocation getFileLoc(unsigned ID) { |
| 95 | assert((ID & MacroIDBit) == 0 && "Ran out of source locations!"); |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 96 | SourceLocation L; |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 97 | L.ID = ID; |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 98 | return L; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 99 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 101 | static SourceLocation getMacroLoc(unsigned ID) { |
| 102 | assert((ID & MacroIDBit) == 0 && "Ran out of source locations!"); |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 103 | SourceLocation L; |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 104 | L.ID = MacroIDBit | ID; |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 105 | return L; |
| 106 | } |
Chris Lattner | 4d10ef1 | 2009-01-19 06:55:08 +0000 | [diff] [blame] | 107 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 108 | |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 109 | /// getFileLocWithOffset - Return a source location with the specified offset |
| 110 | /// from this file SourceLocation. |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 111 | SourceLocation getFileLocWithOffset(int Offset) const { |
Chris Lattner | de7aeef | 2009-01-26 00:43:02 +0000 | [diff] [blame] | 112 | assert(((getOffset()+Offset) & MacroIDBit) == 0 && "invalid location"); |
| 113 | SourceLocation L; |
| 114 | L.ID = ID+Offset; |
| 115 | return L; |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 116 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 118 | /// getRawEncoding - When a SourceLocation itself cannot be used, this returns |
| 119 | /// an (opaque) 32-bit integer encoding for it. This should only be passed |
| 120 | /// to SourceLocation::getFromRawEncoding, it should not be inspected |
| 121 | /// directly. |
| 122 | unsigned getRawEncoding() const { return ID; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
| 124 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 125 | /// getFromRawEncoding - Turn a raw encoding of a SourceLocation object into |
| 126 | /// a real SourceLocation. |
| 127 | static SourceLocation getFromRawEncoding(unsigned Encoding) { |
| 128 | SourceLocation X; |
| 129 | X.ID = Encoding; |
| 130 | return X; |
| 131 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Chris Lattner | ae50fa0 | 2009-03-05 00:00:31 +0000 | [diff] [blame] | 133 | void print(llvm::raw_ostream &OS, const SourceManager &SM) const; |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 134 | void dump(const SourceManager &SM) const; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) { |
| 138 | return LHS.getRawEncoding() == RHS.getRawEncoding(); |
| 139 | } |
| 140 | |
| 141 | inline bool operator!=(const SourceLocation &LHS, const SourceLocation &RHS) { |
| 142 | return !(LHS == RHS); |
| 143 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 144 | |
Chris Lattner | 6fda54c | 2009-01-19 07:00:35 +0000 | [diff] [blame] | 145 | inline bool operator<(const SourceLocation &LHS, const SourceLocation &RHS) { |
| 146 | return LHS.getRawEncoding() < RHS.getRawEncoding(); |
| 147 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 148 | |
| 149 | /// SourceRange - a trival tuple used to represent a source range. |
| 150 | class SourceRange { |
| 151 | SourceLocation B; |
| 152 | SourceLocation E; |
| 153 | public: |
| 154 | SourceRange(): B(SourceLocation()), E(SourceLocation()) {} |
| 155 | SourceRange(SourceLocation loc) : B(loc), E(loc) {} |
| 156 | SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 158 | SourceLocation getBegin() const { return B; } |
| 159 | SourceLocation getEnd() const { return E; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Chris Lattner | e80a59c | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 161 | void setBegin(SourceLocation b) { B = b; } |
| 162 | void setEnd(SourceLocation e) { E = e; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 164 | bool isValid() const { return B.isValid() && E.isValid(); } |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 165 | bool isInvalid() const { return !isValid(); } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 166 | |
Ted Kremenek | a898283 | 2009-03-28 17:32:39 +0000 | [diff] [blame] | 167 | bool operator==(const SourceRange &X) const { |
| 168 | return B == X.B && E == X.E; |
| 169 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | |
Ted Kremenek | a898283 | 2009-03-28 17:32:39 +0000 | [diff] [blame] | 171 | bool operator!=(const SourceRange &X) const { |
| 172 | return B != X.B || E != X.E; |
| 173 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 174 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
Chris Lattner | a50bd54 | 2009-01-16 23:03:56 +0000 | [diff] [blame] | 176 | /// FullSourceLoc - A SourceLocation and its associated SourceManager. Useful |
| 177 | /// for argument passing to functions that expect both objects. |
| 178 | class FullSourceLoc : public SourceLocation { |
Chris Lattner | 5c5db4e | 2010-04-20 20:49:23 +0000 | [diff] [blame^] | 179 | const SourceManager *SrcMgr; |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 180 | public: |
Ted Kremenek | 3632a35 | 2009-01-28 20:46:26 +0000 | [diff] [blame] | 181 | /// Creates a FullSourceLoc where isValid() returns false. |
Chris Lattner | 5c5db4e | 2010-04-20 20:49:23 +0000 | [diff] [blame^] | 182 | explicit FullSourceLoc() : SrcMgr(0) {} |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 183 | |
Chris Lattner | 5c5db4e | 2010-04-20 20:49:23 +0000 | [diff] [blame^] | 184 | explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM) |
Chris Lattner | a50bd54 | 2009-01-16 23:03:56 +0000 | [diff] [blame] | 185 | : SourceLocation(Loc), SrcMgr(&SM) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 186 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 187 | const SourceManager &getManager() const { |
| 188 | assert(SrcMgr && "SourceManager is NULL."); |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 189 | return *SrcMgr; |
| 190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 191 | |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 192 | FileID getFileID() const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 194 | FullSourceLoc getInstantiationLoc() const; |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 195 | FullSourceLoc getSpellingLoc() const; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 196 | |
Douglas Gregor | 64e462d | 2010-03-16 20:53:17 +0000 | [diff] [blame] | 197 | unsigned getInstantiationLineNumber(bool *Invalid = 0) const; |
| 198 | unsigned getInstantiationColumnNumber(bool *Invalid = 0) const; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 199 | |
Douglas Gregor | 64e462d | 2010-03-16 20:53:17 +0000 | [diff] [blame] | 200 | unsigned getSpellingLineNumber(bool *Invalid = 0) const; |
| 201 | unsigned getSpellingColumnNumber(bool *Invalid = 0) const; |
Chris Lattner | 5c38b63 | 2008-09-29 21:46:13 +0000 | [diff] [blame] | 202 | |
Douglas Gregor | a543016 | 2010-03-16 20:46:42 +0000 | [diff] [blame] | 203 | const char *getCharacterData(bool *Invalid = 0) const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 204 | |
Douglas Gregor | aae58b0 | 2010-03-16 20:01:30 +0000 | [diff] [blame] | 205 | const llvm::MemoryBuffer* getBuffer(bool *Invalid = 0) const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 206 | |
Benjamin Kramer | ceafc4b | 2010-03-16 14:48:07 +0000 | [diff] [blame] | 207 | /// getBufferData - Return a StringRef to the source buffer data for the |
| 208 | /// specified FileID. |
Douglas Gregor | aae58b0 | 2010-03-16 20:01:30 +0000 | [diff] [blame] | 209 | llvm::StringRef getBufferData(bool *Invalid = 0) const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Ted Kremenek | 321abd4 | 2009-03-10 05:13:43 +0000 | [diff] [blame] | 211 | /// getDecomposedLoc - Decompose the specified location into a raw FileID + |
| 212 | /// Offset pair. The first element is the FileID, the second is the |
| 213 | /// offset from the start of the buffer of the location. |
| 214 | std::pair<FileID, unsigned> getDecomposedLoc() const; |
| 215 | |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 216 | bool isInSystemHeader() const; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | |
Chris Lattner | 5c38b63 | 2008-09-29 21:46:13 +0000 | [diff] [blame] | 218 | /// Prints information about this FullSourceLoc to stderr. Useful for |
| 219 | /// debugging. |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 220 | void dump() const { SourceLocation::dump(*SrcMgr); } |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 221 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 222 | friend inline bool |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 223 | operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) { |
| 224 | return LHS.getRawEncoding() == RHS.getRawEncoding() && |
| 225 | LHS.SrcMgr == RHS.SrcMgr; |
| 226 | } |
| 227 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 228 | friend inline bool |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 229 | operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) { |
| 230 | return !(LHS == RHS); |
| 231 | } |
| 232 | |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 233 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 235 | /// PresumedLoc - This class represents an unpacked "presumed" location which |
| 236 | /// can be presented to the user. A 'presumed' location can be modified by |
| 237 | /// #line and GNU line marker directives and is always the instantiation point |
| 238 | /// of a normal location. |
| 239 | /// |
| 240 | /// You can get a PresumedLoc from a SourceLocation with SourceManager. |
| 241 | class PresumedLoc { |
| 242 | const char *Filename; |
| 243 | unsigned Line, Col; |
| 244 | SourceLocation IncludeLoc; |
| 245 | public: |
| 246 | PresumedLoc() : Filename(0) {} |
| 247 | PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL) |
| 248 | : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) { |
| 249 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 250 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 251 | /// isInvalid - Return true if this object is invalid or uninitialized. This |
| 252 | /// occurs when created with invalid source locations or when walking off |
| 253 | /// the top of a #include stack. |
| 254 | bool isInvalid() const { return Filename == 0; } |
| 255 | bool isValid() const { return Filename != 0; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 256 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 257 | /// getFilename - Return the presumed filename of this location. This can be |
| 258 | /// affected by #line etc. |
| 259 | const char *getFilename() const { return Filename; } |
| 260 | |
| 261 | /// getLine - Return the presumed line number of this location. This can be |
| 262 | /// affected by #line etc. |
| 263 | unsigned getLine() const { return Line; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 | |
Chris Lattner | b9c3f96 | 2009-01-27 07:57:44 +0000 | [diff] [blame] | 265 | /// getColumn - Return the presumed column number of this location. This can |
| 266 | /// not be affected by #line, but is packaged here for convenience. |
| 267 | unsigned getColumn() const { return Col; } |
| 268 | |
| 269 | /// getIncludeLoc - Return the presumed include location of this location. |
| 270 | /// This can be affected by GNU linemarker directives. |
| 271 | SourceLocation getIncludeLoc() const { return IncludeLoc; } |
| 272 | }; |
| 273 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 274 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 275 | } // end namespace clang |
| 276 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 277 | namespace llvm { |
| 278 | /// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and |
| 279 | /// DenseSets. |
| 280 | template <> |
| 281 | struct DenseMapInfo<clang::FileID> { |
| 282 | static inline clang::FileID getEmptyKey() { |
| 283 | return clang::FileID(); |
| 284 | } |
| 285 | static inline clang::FileID getTombstoneKey() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | return clang::FileID::getSentinel(); |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 287 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 289 | static unsigned getHashValue(clang::FileID S) { |
| 290 | return S.getHashValue(); |
| 291 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 293 | static bool isEqual(clang::FileID LHS, clang::FileID RHS) { |
| 294 | return LHS == RHS; |
| 295 | } |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 296 | }; |
Chris Lattner | 06159e8 | 2009-12-15 07:26:51 +0000 | [diff] [blame] | 297 | |
| 298 | template <> |
| 299 | struct isPodLike<clang::SourceLocation> { static const bool value = true; }; |
| 300 | template <> |
| 301 | struct isPodLike<clang::FileID> { static const bool value = true; }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 302 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 303 | } // end namespace llvm |
| 304 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 305 | #endif |