1 //===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SMLoc class. This class encapsulates a location in
11 // source code for use in diagnostics.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_SMLOC_H
16 #define LLVM_SUPPORT_SMLOC_H
18 #include "llvm/ADT/None.h"
23 /// Represents a location in source code.
25 const char *Ptr = nullptr;
30 bool isValid() const { return Ptr != nullptr; }
32 bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
33 bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
35 const char *getPointer() const { return Ptr; }
37 static SMLoc getFromPointer(const char *Ptr) {
44 /// Represents a range in source code.
46 /// SMRange is implemented using a half-open range, as is the convention in C++.
47 /// In the string "abc", the range (1,3] represents the substring "bc", and the
48 /// range (2,2] represents an empty range between the characters "b" and "c".
55 SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
56 assert(Start.isValid() == End.isValid() &&
57 "Start and end should either both be valid or both be invalid!");
60 bool isValid() const { return Start.isValid(); }
63 } // end namespace llvm
65 #endif // LLVM_SUPPORT_SMLOC_H