SourceLocation.h revision 5a4374812c56aa60672e291b07e14d3696bbb5a6
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- SourceLocation.h - Compact identifier for Source Files -*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the SourceLocation class.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_SOURCELOCATION_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_SOURCELOCATION_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17686775deca8b8685eb90801495880e3abdd844c2Chris Lattner#include "clang/Basic/LLVM.h"
180827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis#include "llvm/Support/PointerLikeTypeTraits.h"
193632a35e811096da86d957c3e6ba0e73d75782f5Ted Kremenek#include <utility>
208f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis#include <functional>
21ae50fa0a9e7217b043ed4ffe175af4b26dc90f34Chris Lattner#include <cassert>
229dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner
239c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremeneknamespace llvm {
242b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  class MemoryBuffer;
252b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  template <typename T> struct DenseMapInfo;
2606159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  template <typename T> struct isPodLike;
279c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek}
289c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenekclass SourceManager;
321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
332b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner/// FileID - This is an opaque identifier used by SourceManager which refers to
342b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner/// a source file (MemoryBuffer) along with its #include path and #line data.
352b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner///
362b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnerclass FileID {
37f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// ID - Opaque identifier, 0 is "invalid". >0 is this module, <-1 is
38f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// something loaded from another module.
39f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  int ID;
402b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnerpublic:
412b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  FileID() : ID(0) {}
421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
432b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool isInvalid() const { return ID == 0; }
441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
452b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator==(const FileID &RHS) const { return ID == RHS.ID; }
462b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator<(const FileID &RHS) const { return ID < RHS.ID; }
472b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator<=(const FileID &RHS) const { return ID <= RHS.ID; }
482b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator!=(const FileID &RHS) const { return !(*this == RHS); }
492b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator>(const FileID &RHS) const { return RHS < *this; }
502b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator>=(const FileID &RHS) const { return RHS <= *this; }
511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  static FileID getSentinel() { return get(-1); }
53f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  unsigned getHashValue() const { return static_cast<unsigned>(ID); }
541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
552b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnerprivate:
562b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  friend class SourceManager;
5731d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  friend class ASTWriter;
5831d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  friend class ASTReader;
5931d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor
60f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  static FileID get(int V) {
612b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    FileID F;
622b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    F.ID = V;
632b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    return F;
642b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  }
65f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  int getOpaqueValue() const { return ID; }
662b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner};
671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
69f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// \brief Encodes a location in the source. The SourceManager can decode this
70f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// to get at the full include stack, line and column information.
71f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor///
72f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// Technically, a source location is simply an offset into the manager's view
73f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// of the input source, which is all input buffers (including macro
743201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// expansions) concatenated in an effectively arbitrary order. The manager
753201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// actually maintains two blocks of input buffers. One, starting at offset
763201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// 0 and growing upwards, contains all buffers from this module. The other,
77f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// starting at the highest possible offset and growing downwards, contains
78f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// buffers of loaded modules.
79f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor///
80f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// In addition, one bit of SourceLocation is used for quick access to the
813201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// information whether the location is in a file or a macro expansion.
82f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor///
83f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// It is important that this type remains small. It is currently 32 bits wide.
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SourceLocation {
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ID;
86bcc2a67e5180612417727cbdd8afd0f79fdf726dChris Lattner  friend class SourceManager;
875a4374812c56aa60672e291b07e14d3696bbb5a6Argyrios Kyrtzidis  friend class ASTReader;
885a4374812c56aa60672e291b07e14d3696bbb5a6Argyrios Kyrtzidis  friend class ASTWriter;
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum {
90de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    MacroIDBit = 1U << 31
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
929ebac5e0dab6f99717e3ff169c45048966146b2eChris Lattnerpublic:
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
94f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  SourceLocation() : ID(0) {}
951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  bool isFileID() const  { return (ID & MacroIDBit) == 0; }
97de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  bool isMacroID() const { return (ID & MacroIDBit) != 0; }
981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief Return true if this is a valid SourceLocation object.
100b7489d8129136437953d412e2a6cf0ef87f4a461Chris Lattner  ///
101f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// Invalid SourceLocations are often used when events have no corresponding
102f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// location in the source (e.g. a diagnostic is required for a command line
103f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// option).
104b7489d8129136437953d412e2a6cf0ef87f4a461Chris Lattner  bool isValid() const { return ID != 0; }
105b7489d8129136437953d412e2a6cf0ef87f4a461Chris Lattner  bool isInvalid() const { return ID == 0; }
1061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1076fda54c19321673965536b0a8f7236f635cf9730Chris Lattnerprivate:
108f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief Return the offset into the manager's global input view.
109de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  unsigned getOffset() const {
110de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    return ID & ~MacroIDBit;
1114d10ef18c32eae35be07e0d8d18b5ff485b4c5f9Chris Lattner  }
1126fda54c19321673965536b0a8f7236f635cf9730Chris Lattner
113de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  static SourceLocation getFileLoc(unsigned ID) {
114de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
1159dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner    SourceLocation L;
116de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    L.ID = ID;
1179dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner    return L;
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
120de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  static SourceLocation getMacroLoc(unsigned ID) {
121de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
122d1623a81992a24abbfcd5520b32a0dd90857b8a8Chris Lattner    SourceLocation L;
123de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    L.ID = MacroIDBit | ID;
1249dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner    return L;
1259dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner  }
1264d10ef18c32eae35be07e0d8d18b5ff485b4c5f9Chris Lattnerpublic:
1271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1289dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner  /// getFileLocWithOffset - Return a source location with the specified offset
1299dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner  /// from this file SourceLocation.
130d1623a81992a24abbfcd5520b32a0dd90857b8a8Chris Lattner  SourceLocation getFileLocWithOffset(int Offset) const {
131f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor    assert(((getOffset()+Offset) & MacroIDBit) == 0 &&
132f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor           "offset overflow or macro loc");
133de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    SourceLocation L;
134de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    L.ID = ID+Offset;
135de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    return L;
1369dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner  }
1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getRawEncoding - When a SourceLocation itself cannot be used, this returns
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an (opaque) 32-bit integer encoding for it.  This should only be passed
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// to SourceLocation::getFromRawEncoding, it should not be inspected
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// directly.
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getRawEncoding() const { return ID; }
1431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getFromRawEncoding - Turn a raw encoding of a SourceLocation object into
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a real SourceLocation.
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SourceLocation getFromRawEncoding(unsigned Encoding) {
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation X;
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    X.ID = Encoding;
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return X;
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  /// getPtrEncoding - When a SourceLocation itself cannot be used, this returns
153dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  /// an (opaque) pointer encoding for it.  This should only be passed
154dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  /// to SourceLocation::getFromPtrEncoding, it should not be inspected
155dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  /// directly.
156dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  void* getPtrEncoding() const {
157dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    // Double cast to avoid a warning "cast to pointer from integer of different
158dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    // size".
159dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    return (void*)(uintptr_t)getRawEncoding();
160dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  }
161dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin
162dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  /// getFromPtrEncoding - Turn a pointer encoding of a SourceLocation object
163dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  /// into a real SourceLocation.
164dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  static SourceLocation getFromPtrEncoding(void *Encoding) {
165dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    return getFromRawEncoding((unsigned)(uintptr_t)Encoding);
166dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  }
167dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin
1688cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void print(raw_ostream &OS, const SourceManager &SM) const;
169b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  void dump(const SourceManager &SM) const;
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) {
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return LHS.getRawEncoding() == RHS.getRawEncoding();
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline bool operator!=(const SourceLocation &LHS, const SourceLocation &RHS) {
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return !(LHS == RHS);
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1806fda54c19321673965536b0a8f7236f635cf9730Chris Lattnerinline bool operator<(const SourceLocation &LHS, const SourceLocation &RHS) {
1816fda54c19321673965536b0a8f7236f635cf9730Chris Lattner  return LHS.getRawEncoding() < RHS.getRawEncoding();
1826fda54c19321673965536b0a8f7236f635cf9730Chris Lattner}
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// SourceRange - a trival tuple used to represent a source range.
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SourceRange {
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation B;
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation E;
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange(): B(SourceLocation()), E(SourceLocation()) {}
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange(SourceLocation loc) : B(loc), E(loc) {}
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {}
1921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
193311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getBegin() const { return B; }
194311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getEnd() const { return E; }
1951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
196e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner  void setBegin(SourceLocation b) { B = b; }
197e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner  void setEnd(SourceLocation e) { E = e; }
1981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isValid() const { return B.isValid() && E.isValid(); }
200782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  bool isInvalid() const { return !isValid(); }
2011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
202a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  bool operator==(const SourceRange &X) const {
203a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek    return B == X.B && E == X.E;
204a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  }
2051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
206a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  bool operator!=(const SourceRange &X) const {
207a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek    return B != X.B || E != X.E;
208a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  }
20919a95bcf3561ed977c48d5f2a2793b60a8c8e573Ted Kremenek};
2100a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2110a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// CharSourceRange - This class represents a character granular source range.
2120a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// The underlying SourceRange can either specify the starting/ending character
2130a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// of the range, or it can specify the start or the range and the start of the
2140a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// last token of the range (a "token range").  In the token range case, the
2150a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// size of the last token must be measured to determine the actual end of the
2160a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// range.
2170a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattnerclass CharSourceRange {
2180a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  SourceRange Range;
2190a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool IsTokenRange;
2200a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattnerpublic:
2210a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  CharSourceRange() : IsTokenRange(false) {}
2220a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  CharSourceRange(SourceRange R, bool ITR) : Range(R),IsTokenRange(ITR){}
2230a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2240a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getTokenRange(SourceRange R) {
2250a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    CharSourceRange Result;
2260a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    Result.Range = R;
2270a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    Result.IsTokenRange = true;
2280a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return Result;
2290a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2300a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2310a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getCharRange(SourceRange R) {
2320a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    CharSourceRange Result;
2330a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    Result.Range = R;
2340a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    Result.IsTokenRange = false;
2350a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return Result;
2360a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2370a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2380a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E) {
2390a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return getTokenRange(SourceRange(B, E));
2400a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2410a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getCharRange(SourceLocation B, SourceLocation E) {
2420a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return getCharRange(SourceRange(B, E));
2430a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2440a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2450a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  /// isTokenRange - Return true if the end of this range specifies the start of
2460a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  /// the last token.  Return false if the end of this range specifies the last
2470a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  /// character in the range.
2480a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool isTokenRange() const { return IsTokenRange; }
2490a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2500a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  SourceLocation getBegin() const { return Range.getBegin(); }
2510a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  SourceLocation getEnd() const { return Range.getEnd(); }
2520a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  const SourceRange &getAsRange() const { return Range; }
2530a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2540a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  void setBegin(SourceLocation b) { Range.setBegin(b); }
2550a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  void setEnd(SourceLocation e) { Range.setEnd(e); }
2560a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2570a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool isValid() const { return Range.isValid(); }
2580a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool isInvalid() const { return !isValid(); }
2590a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner};
2601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
261a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattner/// FullSourceLoc - A SourceLocation and its associated SourceManager.  Useful
262a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattner/// for argument passing to functions that expect both objects.
263a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattnerclass FullSourceLoc : public SourceLocation {
2645c5db4e94bd1243ba92563acba51ba66afa94917Chris Lattner  const SourceManager *SrcMgr;
265a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenekpublic:
2663632a35e811096da86d957c3e6ba0e73d75782f5Ted Kremenek  /// Creates a FullSourceLoc where isValid() returns false.
2675c5db4e94bd1243ba92563acba51ba66afa94917Chris Lattner  explicit FullSourceLoc() : SrcMgr(0) {}
268a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek
2695c5db4e94bd1243ba92563acba51ba66afa94917Chris Lattner  explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
270a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattner    : SourceLocation(Loc), SrcMgr(&SM) {}
2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
272b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  const SourceManager &getManager() const {
273b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner    assert(SrcMgr && "SourceManager is NULL.");
274a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek    return *SrcMgr;
275a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek  }
2761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2773b4d5e955e819dd3a4bed37ea2e47d6e4cb05274Chris Lattner  FileID getFileID() const;
2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
279402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth  FullSourceLoc getExpansionLoc() const;
280df7c17a8d02fe09a3466786bae3e40fc3252687aChris Lattner  FullSourceLoc getSpellingLoc() const;
2819c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek
282642116259e8df6286063a17361c20e95b5017a0aChandler Carruth  unsigned getExpansionLineNumber(bool *Invalid = 0) const;
283a77c031cb66f75d22672070052cc6e0205289ff8Chandler Carruth  unsigned getExpansionColumnNumber(bool *Invalid = 0) const;
2849c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek
28564e462dff03492c586be0349ec6aa3ad5cd92720Douglas Gregor  unsigned getSpellingLineNumber(bool *Invalid = 0) const;
28664e462dff03492c586be0349ec6aa3ad5cd92720Douglas Gregor  unsigned getSpellingColumnNumber(bool *Invalid = 0) const;
2875c38b6388dc44dcb8467a9e0f22d93db7221717eChris Lattner
288a543016fe07030f695d6d56fd22c8c8da617e0d7Douglas Gregor  const char *getCharacterData(bool *Invalid = 0) const;
2891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
290aae58b0c3efb5fa9f97a3e4b1c1a2d31077efe5bDouglas Gregor  const llvm::MemoryBuffer* getBuffer(bool *Invalid = 0) const;
2911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
292ceafc4b63599d14f0b5b10ff92e22bf242682dceBenjamin Kramer  /// getBufferData - Return a StringRef to the source buffer data for the
293ceafc4b63599d14f0b5b10ff92e22bf242682dceBenjamin Kramer  /// specified FileID.
294686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getBufferData(bool *Invalid = 0) const;
2951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
296321abd4583dc02a254489132c5ccbe125d18ce4fTed Kremenek  /// getDecomposedLoc - Decompose the specified location into a raw FileID +
297321abd4583dc02a254489132c5ccbe125d18ce4fTed Kremenek  /// Offset pair.  The first element is the FileID, the second is the
298321abd4583dc02a254489132c5ccbe125d18ce4fTed Kremenek  /// offset from the start of the buffer of the location.
299321abd4583dc02a254489132c5ccbe125d18ce4fTed Kremenek  std::pair<FileID, unsigned> getDecomposedLoc() const;
300321abd4583dc02a254489132c5ccbe125d18ce4fTed Kremenek
3017bfaaaecb3113f955db31e8d8a51acffd1bc0c27Nico Weber  bool isInSystemHeader() const;
3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3030827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Determines the order of 2 source locations in the translation unit.
3040827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
3050827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \returns true if this source location comes before 'Loc', false otherwise.
3060827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  bool isBeforeInTranslationUnitThan(SourceLocation Loc) const;
3070827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
3080827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Determines the order of 2 source locations in the translation unit.
3090827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
3100827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \returns true if this source location comes before 'Loc', false otherwise.
3110827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  bool isBeforeInTranslationUnitThan(FullSourceLoc Loc) const {
3120827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    assert(Loc.isValid());
3130827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    assert(SrcMgr == Loc.SrcMgr && "Loc comes from another SourceManager!");
3140827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    return isBeforeInTranslationUnitThan((SourceLocation)Loc);
3150827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  }
3160827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
3178f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis  /// \brief Comparison function class, useful for sorting FullSourceLocs.
3188f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis  struct BeforeThanCompare : public std::binary_function<FullSourceLoc,
3198f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis                                                         FullSourceLoc, bool> {
3208f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis    bool operator()(const FullSourceLoc& lhs, const FullSourceLoc& rhs) const {
3218f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis      return lhs.isBeforeInTranslationUnitThan(rhs);
3228f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis    }
3238f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis  };
3248f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis
3255c38b6388dc44dcb8467a9e0f22d93db7221717eChris Lattner  /// Prints information about this FullSourceLoc to stderr. Useful for
3265c38b6388dc44dcb8467a9e0f22d93db7221717eChris Lattner  ///  debugging.
327b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  void dump() const { SourceLocation::dump(*SrcMgr); }
328a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek
3291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  friend inline bool
3300b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
3310b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor    return LHS.getRawEncoding() == RHS.getRawEncoding() &&
3320b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor          LHS.SrcMgr == RHS.SrcMgr;
3330b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  }
334a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattner
3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  friend inline bool
3360b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
3370b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor    return !(LHS == RHS);
3380b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  }
3390b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
3400b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor};
3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
342b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner/// PresumedLoc - This class represents an unpacked "presumed" location which
343b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner/// can be presented to the user.  A 'presumed' location can be modified by
3443201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// #line and GNU line marker directives and is always the expansion point of
3453201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// a normal location.
346b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner///
347b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner/// You can get a PresumedLoc from a SourceLocation with SourceManager.
348b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattnerclass PresumedLoc {
349b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  const char *Filename;
350b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  unsigned Line, Col;
351b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  SourceLocation IncludeLoc;
352b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattnerpublic:
353b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  PresumedLoc() : Filename(0) {}
354b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
355b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner    : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {
356b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  }
3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
358b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// isInvalid - Return true if this object is invalid or uninitialized. This
359b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// occurs when created with invalid source locations or when walking off
360b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// the top of a #include stack.
361b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  bool isInvalid() const { return Filename == 0; }
362b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  bool isValid() const { return Filename != 0; }
3631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
364b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// getFilename - Return the presumed filename of this location.  This can be
365b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// affected by #line etc.
366b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  const char *getFilename() const { return Filename; }
367b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner
368b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// getLine - Return the presumed line number of this location.  This can be
369b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// affected by #line etc.
370b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  unsigned getLine() const { return Line; }
3711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
372b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// getColumn - Return the presumed column number of this location.  This can
373b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// not be affected by #line, but is packaged here for convenience.
374b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  unsigned getColumn() const { return Col; }
375b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner
376b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// getIncludeLoc - Return the presumed include location of this location.
377b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// This can be affected by GNU linemarker directives.
378b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  SourceLocation getIncludeLoc() const { return IncludeLoc; }
379b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner};
380b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner
3811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
382beb7713c6102687f7e49e27b8228e84a69d8f6c6Ted Kremenek}  // end namespace clang
38319a95bcf3561ed977c48d5f2a2793b60a8c8e573Ted Kremenek
3842b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnernamespace llvm {
3852b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  /// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
3862b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  /// DenseSets.
3872b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  template <>
3882b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  struct DenseMapInfo<clang::FileID> {
3892b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static inline clang::FileID getEmptyKey() {
3902b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner      return clang::FileID();
3912b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
3922b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static inline clang::FileID getTombstoneKey() {
3931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return clang::FileID::getSentinel();
3942b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
3951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3962b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static unsigned getHashValue(clang::FileID S) {
3972b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner      return S.getHashValue();
3982b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
3991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4002b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static bool isEqual(clang::FileID LHS, clang::FileID RHS) {
4012b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner      return LHS == RHS;
4022b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
4032b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  };
40406159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner
40506159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  template <>
40606159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  struct isPodLike<clang::SourceLocation> { static const bool value = true; };
40706159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  template <>
40806159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  struct isPodLike<clang::FileID> { static const bool value = true; };
4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4100827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  // Teach SmallPtrSet how to handle SourceLocation.
4110827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  template<>
4120827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  class PointerLikeTypeTraits<clang::SourceLocation> {
4130827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  public:
4140827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    static inline void *getAsVoidPointer(clang::SourceLocation L) {
415dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin      return L.getPtrEncoding();
4160827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    }
4170827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    static inline clang::SourceLocation getFromVoidPointer(void *P) {
4180827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      return clang::SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)P);
4190827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    }
4200827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    enum { NumLowBitsAvailable = 0 };
4210827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  };
4220827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
4232b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner}  // end namespace llvm
4242b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
426