Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:34

0001 //===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the SMLoc class.  This class encapsulates a location in
0010 // source code for use in diagnostics.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_SUPPORT_SMLOC_H
0015 #define LLVM_SUPPORT_SMLOC_H
0016 
0017 #include <cassert>
0018 #include <optional>
0019 
0020 namespace llvm {
0021 
0022 /// Represents a location in source code.
0023 class SMLoc {
0024   const char *Ptr = nullptr;
0025 
0026 public:
0027   constexpr SMLoc() = default;
0028 
0029   constexpr bool isValid() const { return Ptr != nullptr; }
0030 
0031   constexpr bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
0032   constexpr bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
0033 
0034   constexpr const char *getPointer() const { return Ptr; }
0035 
0036   static SMLoc getFromPointer(const char *Ptr) {
0037     SMLoc L;
0038     L.Ptr = Ptr;
0039     return L;
0040   }
0041 };
0042 
0043 /// Represents a range in source code.
0044 ///
0045 /// SMRange is implemented using a half-open range, as is the convention in C++.
0046 /// In the string "abc", the range [1,3) represents the substring "bc", and the
0047 /// range [2,2) represents an empty range between the characters "b" and "c".
0048 class SMRange {
0049 public:
0050   SMLoc Start, End;
0051 
0052   SMRange() = default;
0053   SMRange(std::nullopt_t) {}
0054   SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
0055     assert(Start.isValid() == End.isValid() &&
0056            "Start and End should either both be valid or both be invalid!");
0057   }
0058 
0059   bool isValid() const { return Start.isValid(); }
0060 };
0061 
0062 } // end namespace llvm
0063 
0064 #endif // LLVM_SUPPORT_SMLOC_H