LLVM  8.0.1
SMLoc.h
Go to the documentation of this file.
1 //===- SMLoc.h - Source location for use with diagnostics -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the SMLoc class. This class encapsulates a location in
11 // source code for use in diagnostics.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_SUPPORT_SMLOC_H
16 #define LLVM_SUPPORT_SMLOC_H
17 
18 #include "llvm/ADT/None.h"
19 #include <cassert>
20 
21 namespace llvm {
22 
23 /// Represents a location in source code.
24 class SMLoc {
25  const char *Ptr = nullptr;
26 
27 public:
28  SMLoc() = default;
29 
30  bool isValid() const { return Ptr != nullptr; }
31 
32  bool operator==(const SMLoc &RHS) const { return RHS.Ptr == Ptr; }
33  bool operator!=(const SMLoc &RHS) const { return RHS.Ptr != Ptr; }
34 
35  const char *getPointer() const { return Ptr; }
36 
37  static SMLoc getFromPointer(const char *Ptr) {
38  SMLoc L;
39  L.Ptr = Ptr;
40  return L;
41  }
42 };
43 
44 /// Represents a range in source code.
45 ///
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".
49 class SMRange {
50 public:
51  SMLoc Start, End;
52 
53  SMRange() = default;
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!");
58  }
59 
60  bool isValid() const { return Start.isValid(); }
61 };
62 
63 } // end namespace llvm
64 
65 #endif // LLVM_SUPPORT_SMLOC_H
Represents a range in source code.
Definition: SMLoc.h:49
This class represents lattice values for constants.
Definition: AllocatorList.h:24
NoneType
A simple null object to allow implicit construction of Optional<T> and similar types without having t...
Definition: None.h:23
bool operator!=(const SMLoc &RHS) const
Definition: SMLoc.h:33
SMLoc Start
Definition: SMLoc.h:51
bool operator==(const SMLoc &RHS) const
Definition: SMLoc.h:32
const char * getPointer() const
Definition: SMLoc.h:35
SMRange(NoneType)
Definition: SMLoc.h:54
bool isValid() const
Definition: SMLoc.h:60
SMRange(SMLoc St, SMLoc En)
Definition: SMLoc.h:55
bool isValid() const
Definition: SMLoc.h:30
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:37
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SMLoc()=default
Represents a location in source code.
Definition: SMLoc.h:24