LLVM 19.0.0git
SMLoc.h
Go to the documentation of this file.
1//===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the SMLoc class. This class encapsulates a location in
10// source code for use in diagnostics.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_SMLOC_H
15#define LLVM_SUPPORT_SMLOC_H
16
17#include <cassert>
18#include <optional>
19
20namespace llvm {
21
22/// Represents a location in source code.
23class SMLoc {
24 const char *Ptr = nullptr;
25
26public:
27 constexpr SMLoc() = default;
28
29 constexpr bool isValid() const { return Ptr != nullptr; }
30
31 constexpr bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
32 constexpr bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
33
34 constexpr const char *getPointer() const { return Ptr; }
35
36 static SMLoc getFromPointer(const char *Ptr) {
37 SMLoc L;
38 L.Ptr = Ptr;
39 return L;
40 }
41};
42
43/// Represents a range in source code.
44///
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".
48class SMRange {
49public:
51
52 SMRange() = default;
53 SMRange(std::nullopt_t) {}
54 SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
56 "Start and End should either both be valid or both be invalid!");
57 }
58
59 bool isValid() const { return Start.isValid(); }
60};
61
62} // end namespace llvm
63
64#endif // LLVM_SUPPORT_SMLOC_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Represents a location in source code.
Definition: SMLoc.h:23
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:36
constexpr bool operator!=(const SMLoc &RHS) const
Definition: SMLoc.h:32
constexpr bool operator==(const SMLoc &RHS) const
Definition: SMLoc.h:31
constexpr const char * getPointer() const
Definition: SMLoc.h:34
constexpr bool isValid() const
Definition: SMLoc.h:29
constexpr SMLoc()=default
Represents a range in source code.
Definition: SMLoc.h:48
SMRange(std::nullopt_t)
Definition: SMLoc.h:53
bool isValid() const
Definition: SMLoc.h:59
SMRange()=default
SMLoc Start
Definition: SMLoc.h:50
SMLoc End
Definition: SMLoc.h:50
SMRange(SMLoc St, SMLoc En)
Definition: SMLoc.h:54
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18