SourceLocation.h revision 6bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89
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//===----------------------------------------------------------------------===//
92f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett///
102f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \file
112f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \brief Defines the clang::SourceLocation class and associated facilities.
122f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett///
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_SOURCELOCATION_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_SOURCELOCATION_H
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18686775deca8b8685eb90801495880e3abdd844c2Chris Lattner#include "clang/Basic/LLVM.h"
190ee7d94ece918f22e67d0f09fcbc631c91091adcArgyrios Kyrtzidis#include "llvm/Support/Compiler.h"
2030a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/Support/PointerLikeTypeTraits.h"
21ae50fa0a9e7217b043ed4ffe175af4b26dc90f34Chris Lattner#include <cassert>
2230a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include <functional>
23b328ee55d86acaafd55ebf0e0c84766b29459530Chad Rosier#include <string>
2430a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include <utility>
259dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner
269c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremeneknamespace llvm {
272b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  class MemoryBuffer;
282b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  template <typename T> struct DenseMapInfo;
2906159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  template <typename T> struct isPodLike;
309c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek}
319c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
34a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenekclass SourceManager;
351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
364bd495c2a4fc742dde435115f66c722217975bd2James Dennett/// \brief An opaque identifier used by SourceManager which refers to a
374bd495c2a4fc742dde435115f66c722217975bd2James Dennett/// source file (MemoryBuffer) along with its \#include path and \#line data.
382b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner///
392b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnerclass FileID {
40af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief A mostly-opaque identifier, where 0 is "invalid", >0 is
41af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// this module, and <-1 is something loaded from another module.
42f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  int ID;
432b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnerpublic:
442b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  FileID() : ID(0) {}
451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
462b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool isInvalid() const { return ID == 0; }
471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
482b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator==(const FileID &RHS) const { return ID == RHS.ID; }
492b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator<(const FileID &RHS) const { return ID < RHS.ID; }
502b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator<=(const FileID &RHS) const { return ID <= RHS.ID; }
512b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator!=(const FileID &RHS) const { return !(*this == RHS); }
522b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator>(const FileID &RHS) const { return RHS < *this; }
532b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  bool operator>=(const FileID &RHS) const { return RHS <= *this; }
541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
55f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  static FileID getSentinel() { return get(-1); }
56f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  unsigned getHashValue() const { return static_cast<unsigned>(ID); }
571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
582b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnerprivate:
592b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  friend class SourceManager;
6031d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  friend class ASTWriter;
6131d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  friend class ASTReader;
6231d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor
63f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  static FileID get(int V) {
642b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    FileID F;
652b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    F.ID = V;
662b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    return F;
672b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  }
68f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  int getOpaqueValue() const { return ID; }
692b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner};
701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
72f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// \brief Encodes a location in the source. The SourceManager can decode this
73f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// to get at the full include stack, line and column information.
74f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor///
75f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// Technically, a source location is simply an offset into the manager's view
76f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// of the input source, which is all input buffers (including macro
773201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// expansions) concatenated in an effectively arbitrary order. The manager
783201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// actually maintains two blocks of input buffers. One, starting at offset
793201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// 0 and growing upwards, contains all buffers from this module. The other,
80f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// starting at the highest possible offset and growing downwards, contains
81f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// buffers of loaded modules.
82f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor///
83f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// In addition, one bit of SourceLocation is used for quick access to the
843201f382956ed9beee9fb31229c2835c1208889cChandler Carruth/// information whether the location is in a file or a macro expansion.
85f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor///
86f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor/// It is important that this type remains small. It is currently 32 bits wide.
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SourceLocation {
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned ID;
89bcc2a67e5180612417727cbdd8afd0f79fdf726dChris Lattner  friend class SourceManager;
905a4374812c56aa60672e291b07e14d3696bbb5a6Argyrios Kyrtzidis  friend class ASTReader;
915a4374812c56aa60672e291b07e14d3696bbb5a6Argyrios Kyrtzidis  friend class ASTWriter;
92651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  enum : unsigned {
93de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    MacroIDBit = 1U << 31
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
959ebac5e0dab6f99717e3ff169c45048966146b2eChris Lattnerpublic:
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
97f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  SourceLocation() : ID(0) {}
981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  bool isFileID() const  { return (ID & MacroIDBit) == 0; }
100de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  bool isMacroID() const { return (ID & MacroIDBit) != 0; }
1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief Return true if this is a valid SourceLocation object.
103b7489d8129136437953d412e2a6cf0ef87f4a461Chris Lattner  ///
104f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// Invalid SourceLocations are often used when events have no corresponding
105f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// location in the source (e.g. a diagnostic is required for a command line
106f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// option).
107b7489d8129136437953d412e2a6cf0ef87f4a461Chris Lattner  bool isValid() const { return ID != 0; }
108b7489d8129136437953d412e2a6cf0ef87f4a461Chris Lattner  bool isInvalid() const { return ID == 0; }
1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1106fda54c19321673965536b0a8f7236f635cf9730Chris Lattnerprivate:
111f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief Return the offset into the manager's global input view.
112de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  unsigned getOffset() const {
113de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    return ID & ~MacroIDBit;
1144d10ef18c32eae35be07e0d8d18b5ff485b4c5f9Chris Lattner  }
1156fda54c19321673965536b0a8f7236f635cf9730Chris Lattner
116de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  static SourceLocation getFileLoc(unsigned ID) {
117de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
1189dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner    SourceLocation L;
119de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    L.ID = ID;
1209dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner    return L;
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
123de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner  static SourceLocation getMacroLoc(unsigned ID) {
124de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
125d1623a81992a24abbfcd5520b32a0dd90857b8a8Chris Lattner    SourceLocation L;
126de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    L.ID = MacroIDBit | ID;
1279dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner    return L;
1289dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner  }
1294d10ef18c32eae35be07e0d8d18b5ff485b4c5f9Chris Lattnerpublic:
1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
131a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis  /// \brief Return a source location with the specified offset from this
132a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis  /// SourceLocation.
133a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis  SourceLocation getLocWithOffset(int Offset) const {
134a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis    assert(((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow");
135de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    SourceLocation L;
136de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    L.ID = ID+Offset;
137de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner    return L;
1389dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner  }
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1404bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \brief When a SourceLocation itself cannot be used, this returns
1414bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// an (opaque) 32-bit integer encoding for it.
1424bd495c2a4fc742dde435115f66c722217975bd2James Dennett  ///
1434bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// This should only be passed to SourceLocation::getFromRawEncoding, it
1444bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// should not be inspected directly.
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getRawEncoding() const { return ID; }
1461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1474bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \brief Turn a raw encoding of a SourceLocation object into
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// a real SourceLocation.
1494bd495c2a4fc742dde435115f66c722217975bd2James Dennett  ///
1504bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \see getRawEncoding.
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SourceLocation getFromRawEncoding(unsigned Encoding) {
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SourceLocation X;
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    X.ID = Encoding;
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return X;
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1574bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \brief When a SourceLocation itself cannot be used, this returns
1584bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// an (opaque) pointer encoding for it.
1594bd495c2a4fc742dde435115f66c722217975bd2James Dennett  ///
1604bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// This should only be passed to SourceLocation::getFromPtrEncoding, it
1614bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// should not be inspected directly.
162dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  void* getPtrEncoding() const {
163dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    // Double cast to avoid a warning "cast to pointer from integer of different
164dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    // size".
165dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    return (void*)(uintptr_t)getRawEncoding();
166dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  }
167dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin
1681216015de0a958860082a7fa8b504547197686c3James Dennett  /// \brief Turn a pointer encoding of a SourceLocation object back
169dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  /// into a real SourceLocation.
1704a0beb20655ae9f28d519e088c6ec8dceec59eddJordan Rose  static SourceLocation getFromPtrEncoding(const void *Encoding) {
171dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin    return getFromRawEncoding((unsigned)(uintptr_t)Encoding);
172dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin  }
173dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin
1748cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  void print(raw_ostream &OS, const SourceManager &SM) const;
175651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::string printToString(const SourceManager &SM) const;
176b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  void dump(const SourceManager &SM) const;
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) {
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return LHS.getRawEncoding() == RHS.getRawEncoding();
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline bool operator!=(const SourceLocation &LHS, const SourceLocation &RHS) {
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return !(LHS == RHS);
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1876fda54c19321673965536b0a8f7236f635cf9730Chris Lattnerinline bool operator<(const SourceLocation &LHS, const SourceLocation &RHS) {
1886fda54c19321673965536b0a8f7236f635cf9730Chris Lattner  return LHS.getRawEncoding() < RHS.getRawEncoding();
1896fda54c19321673965536b0a8f7236f635cf9730Chris Lattner}
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
191651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines/// \brief A trivial tuple used to represent a source range.
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass SourceRange {
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation B;
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceLocation E;
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange(): B(SourceLocation()), E(SourceLocation()) {}
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange(SourceLocation loc) : B(loc), E(loc) {}
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {}
1991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
200311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getBegin() const { return B; }
201311ff02fae0392bee6abe7723cdf5a69b2899a47Chris Lattner  SourceLocation getEnd() const { return E; }
2021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
203e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner  void setBegin(SourceLocation b) { B = b; }
204e80a59cc41d42a970466cb020b6f44c5b8831d70Chris Lattner  void setEnd(SourceLocation e) { E = e; }
2051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isValid() const { return B.isValid() && E.isValid(); }
207782f2f52b78d8ca785110398a7f7b56b830b9ac7Ted Kremenek  bool isInvalid() const { return !isValid(); }
2081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
209a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  bool operator==(const SourceRange &X) const {
210a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek    return B == X.B && E == X.E;
211a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  }
2121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
213a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  bool operator!=(const SourceRange &X) const {
214a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek    return B != X.B || E != X.E;
215a898283deb689b2454f3a966ef1cbf81bcb3e3e4Ted Kremenek  }
21619a95bcf3561ed977c48d5f2a2793b60a8c8e573Ted Kremenek};
2170a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
218af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// \brief Represents a character-granular source range.
219af50aab0c317462129d73ae8000c6394c718598dJames Dennett///
2200a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// The underlying SourceRange can either specify the starting/ending character
2211f19c76253ae95153d84355c80342e8eaab81fe1Michael Han/// of the range, or it can specify the start of the range and the start of the
2220a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// last token of the range (a "token range").  In the token range case, the
2230a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// size of the last token must be measured to determine the actual end of the
2240a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner/// range.
2250a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattnerclass CharSourceRange {
2260a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  SourceRange Range;
2270a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool IsTokenRange;
2280a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattnerpublic:
2290a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  CharSourceRange() : IsTokenRange(false) {}
2304a2ef80d896c1bac38ce113ec19a8d509a619288Nico Weber  CharSourceRange(SourceRange R, bool ITR) : Range(R), IsTokenRange(ITR) {}
2310a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2320a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getTokenRange(SourceRange R) {
2334a2ef80d896c1bac38ce113ec19a8d509a619288Nico Weber    return CharSourceRange(R, true);
2340a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2350a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2360a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getCharRange(SourceRange R) {
2374a2ef80d896c1bac38ce113ec19a8d509a619288Nico Weber    return CharSourceRange(R, false);
2380a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2390a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2400a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E) {
2410a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return getTokenRange(SourceRange(B, E));
2420a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2430a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static CharSourceRange getCharRange(SourceLocation B, SourceLocation E) {
2440a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return getCharRange(SourceRange(B, E));
2450a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
2460a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
247af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return true if the end of this range specifies the start of
2480a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  /// the last token.  Return false if the end of this range specifies the last
2490a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  /// character in the range.
2500a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool isTokenRange() const { return IsTokenRange; }
251a83f4d2315dbeb3914868f1ccb8e74fb2ccdbb0cArgyrios Kyrtzidis  bool isCharRange() const { return !IsTokenRange; }
2520a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2530a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  SourceLocation getBegin() const { return Range.getBegin(); }
2540a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  SourceLocation getEnd() const { return Range.getEnd(); }
2550a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  const SourceRange &getAsRange() const { return Range; }
2560a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2570a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  void setBegin(SourceLocation b) { Range.setBegin(b); }
2580a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  void setEnd(SourceLocation e) { Range.setEnd(e); }
2590a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
2600a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool isValid() const { return Range.isValid(); }
2610a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  bool isInvalid() const { return !isValid(); }
2620a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner};
2631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
264af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// \brief A SourceLocation and its associated SourceManager.
265af50aab0c317462129d73ae8000c6394c718598dJames Dennett///
266af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// This is useful for argument passing to functions that expect both objects.
267a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattnerclass FullSourceLoc : public SourceLocation {
2685c5db4e94bd1243ba92563acba51ba66afa94917Chris Lattner  const SourceManager *SrcMgr;
269a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenekpublic:
270af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Creates a FullSourceLoc where isValid() returns \c false.
2716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  explicit FullSourceLoc() : SrcMgr(nullptr) {}
272a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek
2735c5db4e94bd1243ba92563acba51ba66afa94917Chris Lattner  explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
274a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattner    : SourceLocation(Loc), SrcMgr(&SM) {}
2751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
276af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \pre This FullSourceLoc has an associated SourceManager.
277b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  const SourceManager &getManager() const {
278b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner    assert(SrcMgr && "SourceManager is NULL.");
279a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek    return *SrcMgr;
280a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek  }
2811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2823b4d5e955e819dd3a4bed37ea2e47d6e4cb05274Chris Lattner  FileID getFileID() const;
2831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
284402785357ab053dd53f4fdd858b9630a5e0f8badChandler Carruth  FullSourceLoc getExpansionLoc() const;
285df7c17a8d02fe09a3466786bae3e40fc3252687aChris Lattner  FullSourceLoc getSpellingLoc() const;
2869c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek
2876bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  unsigned getExpansionLineNumber(bool *Invalid = nullptr) const;
2886bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  unsigned getExpansionColumnNumber(bool *Invalid = nullptr) const;
2899c728dc4d8da89c73fcae74c9e72d7a83ffd7b6dTed Kremenek
2906bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  unsigned getSpellingLineNumber(bool *Invalid = nullptr) const;
2916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  unsigned getSpellingColumnNumber(bool *Invalid = nullptr) const;
2925c38b6388dc44dcb8467a9e0f22d93db7221717eChris Lattner
2936bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  const char *getCharacterData(bool *Invalid = nullptr) const;
2941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2956bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  const llvm::MemoryBuffer* getBuffer(bool *Invalid = nullptr) const;
2961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
297af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return a StringRef to the source buffer data for the
298ceafc4b63599d14f0b5b10ff92e22bf242682dceBenjamin Kramer  /// specified FileID.
2996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  StringRef getBufferData(bool *Invalid = nullptr) const;
3001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
301af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Decompose the specified location into a raw FileID + Offset pair.
302af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
303af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// The first element is the FileID, the second is the offset from the
304af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// start of the buffer of the location.
305321abd4583dc02a254489132c5ccbe125d18ce4fTed Kremenek  std::pair<FileID, unsigned> getDecomposedLoc() const;
306321abd4583dc02a254489132c5ccbe125d18ce4fTed Kremenek
3077bfaaaecb3113f955db31e8d8a51acffd1bc0c27Nico Weber  bool isInSystemHeader() const;
3081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3090827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Determines the order of 2 source locations in the translation unit.
3100827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
3110827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \returns true if this source location comes before 'Loc', false otherwise.
3120827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  bool isBeforeInTranslationUnitThan(SourceLocation Loc) const;
3130827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
3140827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Determines the order of 2 source locations in the translation unit.
3150827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
3160827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \returns true if this source location comes before 'Loc', false otherwise.
3170827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  bool isBeforeInTranslationUnitThan(FullSourceLoc Loc) const {
3180827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    assert(Loc.isValid());
3190827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    assert(SrcMgr == Loc.SrcMgr && "Loc comes from another SourceManager!");
3200827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    return isBeforeInTranslationUnitThan((SourceLocation)Loc);
3210827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  }
3220827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
3238f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis  /// \brief Comparison function class, useful for sorting FullSourceLocs.
3248f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis  struct BeforeThanCompare : public std::binary_function<FullSourceLoc,
3258f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis                                                         FullSourceLoc, bool> {
3268f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis    bool operator()(const FullSourceLoc& lhs, const FullSourceLoc& rhs) const {
3278f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis      return lhs.isBeforeInTranslationUnitThan(rhs);
3288f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis    }
3298f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis  };
3308f89652be7bb85bdac83c37fec85f20cdd2dfc83Argyrios Kyrtzidis
331af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Prints information about this FullSourceLoc to stderr.
332af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
333af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// This is useful for debugging.
334651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void dump() const;
335a9793ed6a77946c988ee38035baf4cde6ff2e864Ted Kremenek
3361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  friend inline bool
3370b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
3380b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor    return LHS.getRawEncoding() == RHS.getRawEncoding() &&
3390b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor          LHS.SrcMgr == RHS.SrcMgr;
3400b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  }
341a50bd54164393ca3cd08016e7099bdeb531b5014Chris Lattner
3421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  friend inline bool
3430b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
3440b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor    return !(LHS == RHS);
3450b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  }
3460b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
3470b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor};
3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
349af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// \brief Represents an unpacked "presumed" location which can be presented
350af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// to the user.
351af50aab0c317462129d73ae8000c6394c718598dJames Dennett///
352af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// A 'presumed' location can be modified by \#line and GNU line marker
353af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// directives and is always the expansion point of a normal location.
354b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner///
355b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner/// You can get a PresumedLoc from a SourceLocation with SourceManager.
356b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattnerclass PresumedLoc {
357b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  const char *Filename;
358b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  unsigned Line, Col;
359b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  SourceLocation IncludeLoc;
360b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattnerpublic:
3616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  PresumedLoc() : Filename(nullptr) {}
362b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
363b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner    : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {
364b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  }
3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
366af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// \brief Return true if this object is invalid or uninitialized.
367af50aab0c317462129d73ae8000c6394c718598dJames Dennett  ///
368af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// This occurs when created with invalid source locations or when walking
369af50aab0c317462129d73ae8000c6394c718598dJames Dennett  /// off the top of a \#include stack.
3706bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool isInvalid() const { return Filename == nullptr; }
3716bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool isValid() const { return Filename != nullptr; }
3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3734bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \brief Return the presumed filename of this location.
3744bd495c2a4fc742dde435115f66c722217975bd2James Dennett  ///
3754bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// This can be affected by \#line etc.
376b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  const char *getFilename() const { return Filename; }
377b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner
3784bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \brief Return the presumed line number of this location.
3794bd495c2a4fc742dde435115f66c722217975bd2James Dennett  ///
3804bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// This can be affected by \#line etc.
381b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  unsigned getLine() const { return Line; }
3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3834bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \brief Return the presumed column number of this location.
3844bd495c2a4fc742dde435115f66c722217975bd2James Dennett  ///
3854bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// This cannot be affected by \#line, but is packaged here for convenience.
386b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  unsigned getColumn() const { return Col; }
387b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner
3884bd495c2a4fc742dde435115f66c722217975bd2James Dennett  /// \brief Return the presumed include location of this location.
3894bd495c2a4fc742dde435115f66c722217975bd2James Dennett  ///
390b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  /// This can be affected by GNU linemarker directives.
391b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner  SourceLocation getIncludeLoc() const { return IncludeLoc; }
392b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner};
393b9c3f966b103f7cfe8e5e60007c4c8b38f7298ebChris Lattner
3941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
395beb7713c6102687f7e49e27b8228e84a69d8f6c6Ted Kremenek}  // end namespace clang
39619a95bcf3561ed977c48d5f2a2793b60a8c8e573Ted Kremenek
3972b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattnernamespace llvm {
3982b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  /// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
3992b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  /// DenseSets.
4002b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  template <>
4012b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  struct DenseMapInfo<clang::FileID> {
4022b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static inline clang::FileID getEmptyKey() {
4032b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner      return clang::FileID();
4042b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
4052b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static inline clang::FileID getTombstoneKey() {
4061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      return clang::FileID::getSentinel();
4072b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
4081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4092b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static unsigned getHashValue(clang::FileID S) {
4102b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner      return S.getHashValue();
4112b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4132b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    static bool isEqual(clang::FileID LHS, clang::FileID RHS) {
4142b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner      return LHS == RHS;
4152b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner    }
4162b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner  };
41706159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner
41806159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  template <>
41906159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  struct isPodLike<clang::SourceLocation> { static const bool value = true; };
42006159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  template <>
42106159e878569e5f39bf0e8f11b84ac3ad0970597Chris Lattner  struct isPodLike<clang::FileID> { static const bool value = true; };
4221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4230827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  // Teach SmallPtrSet how to handle SourceLocation.
4240827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  template<>
4250827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  class PointerLikeTypeTraits<clang::SourceLocation> {
4260827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  public:
4270827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    static inline void *getAsVoidPointer(clang::SourceLocation L) {
428dec0984fce504a39a7f085774fb67cfd9957be58Jeffrey Yasskin      return L.getPtrEncoding();
4290827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    }
4300827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    static inline clang::SourceLocation getFromVoidPointer(void *P) {
4310827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      return clang::SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)P);
4320827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    }
4330827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    enum { NumLowBitsAvailable = 0 };
4340827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  };
4350827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
4362b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner}  // end namespace llvm
4372b2453a7d8fe732561795431f39ceb2b2a832d84Chris Lattner
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
439