LLVM 22.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
19namespace llvm {
20
21/// Represents a location in source code.
22class SMLoc {
23 const char *Ptr = nullptr;
24
25public:
26 constexpr SMLoc() = default;
27
28 constexpr bool isValid() const { return Ptr != nullptr; }
29
30 constexpr bool operator==(SMLoc RHS) const { return RHS.Ptr == Ptr; }
31 constexpr bool operator!=(SMLoc RHS) const { return RHS.Ptr != Ptr; }
32
33 constexpr const char *getPointer() const { return Ptr; }
34
35 static SMLoc getFromPointer(const char *Ptr) {
36 SMLoc L;
37 L.Ptr = Ptr;
38 return L;
39 }
40};
41
42/// Represents a range in source code.
43///
44/// SMRange is implemented using a half-open range, as is the convention in C++.
45/// In the string "abc", the range [1,3) represents the substring "bc", and the
46/// range [2,2) represents an empty range between the characters "b" and "c".
47class SMRange {
48public:
50
51 SMRange() = default;
52 SMRange(SMLoc St, SMLoc En) : Start(St), End(En) {
53 assert(Start.isValid() == End.isValid() &&
54 "Start and End should either both be valid or both be invalid!");
55 }
56
57 bool isValid() const { return Start.isValid(); }
58};
59
60} // end namespace llvm
61
62#endif // LLVM_SUPPORT_SMLOC_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Value * RHS
Represents a location in source code.
Definition SMLoc.h:22
constexpr bool operator==(SMLoc RHS) const
Definition SMLoc.h:30
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
constexpr const char * getPointer() const
Definition SMLoc.h:33
constexpr bool isValid() const
Definition SMLoc.h:28
constexpr SMLoc()=default
constexpr bool operator!=(SMLoc RHS) const
Definition SMLoc.h:31
bool isValid() const
Definition SMLoc.h:57
SMRange()=default
SMLoc Start
Definition SMLoc.h:49
SMLoc End
Definition SMLoc.h:49
SMRange(SMLoc St, SMLoc En)
Definition SMLoc.h:52
This is an optimization pass for GlobalISel generic memory operations.