1 //===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares the SMLoc class. This class encapsulates a location in
10 // source code for use in diagnostics.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_SMLOC_H
15 #define LLVM_SUPPORT_SMLOC_H
17 #include "llvm/ADT/None.h"
22 /// Represents a location in source code.
24 const char *Ptr = nullptr;
29 bool isValid() const { return Ptr != nullptr; }
31 bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
32 bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
34 const char *getPointer() const { return Ptr; }
36 static SMLoc getFromPointer(const char *Ptr) {
43 /// Represents a range in source code.
45 /// SMRange is implemented using a half-open range, as is the convention in C++.
46 /// In the string "abc", the range [1,3) represents the substring "bc", and the
47 /// range [2,2) represents an empty range between the characters "b" and "c".
54 SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
55 assert(Start.isValid() == End.isValid() &&
56 "Start and End should either both be valid or both be invalid!");
59 bool isValid() const { return Start.isValid(); }
62 } // end namespace llvm
64 #endif // LLVM_SUPPORT_SMLOC_H