clang  7.0.0svn
FileOffset.h
Go to the documentation of this file.
1 //===- FileOffset.h - Offset in a file --------------------------*- 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 #ifndef LLVM_CLANG_EDIT_FILEOFFSET_H
11 #define LLVM_CLANG_EDIT_FILEOFFSET_H
12 
14 #include <tuple>
15 
16 namespace clang {
17 namespace edit {
18 
19 class FileOffset {
20  FileID FID;
21  unsigned Offs = 0;
22 
23 public:
24  FileOffset() = default;
25  FileOffset(FileID fid, unsigned offs) : FID(fid), Offs(offs) {}
26 
27  bool isInvalid() const { return FID.isInvalid(); }
28 
29  FileID getFID() const { return FID; }
30  unsigned getOffset() const { return Offs; }
31 
32  FileOffset getWithOffset(unsigned offset) const {
33  FileOffset NewOffs = *this;
34  NewOffs.Offs += offset;
35  return NewOffs;
36  }
37 
38  friend bool operator==(FileOffset LHS, FileOffset RHS) {
39  return LHS.FID == RHS.FID && LHS.Offs == RHS.Offs;
40  }
41 
42  friend bool operator!=(FileOffset LHS, FileOffset RHS) {
43  return !(LHS == RHS);
44  }
45 
46  friend bool operator<(FileOffset LHS, FileOffset RHS) {
47  return std::tie(LHS.FID, LHS.Offs) < std::tie(RHS.FID, RHS.Offs);
48  }
49 
50  friend bool operator>(FileOffset LHS, FileOffset RHS) {
51  return RHS < LHS;
52  }
53 
54  friend bool operator>=(FileOffset LHS, FileOffset RHS) {
55  return !(LHS < RHS);
56  }
57 
58  friend bool operator<=(FileOffset LHS, FileOffset RHS) {
59  return !(RHS < LHS);
60  }
61 };
62 
63 } // namespace edit
64 } // namespace clang
65 
66 #endif // LLVM_CLANG_EDIT_FILEOFFSET_H
FileOffset(FileID fid, unsigned offs)
Definition: FileOffset.h:25
friend bool operator==(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:38
friend bool operator>(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:50
bool isInvalid() const
FileID getFID() const
Definition: FileOffset.h:29
friend bool operator<(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:46
FileOffset getWithOffset(unsigned offset) const
Definition: FileOffset.h:32
friend bool operator!=(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:42
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
unsigned getOffset() const
Definition: FileOffset.h:30
bool isInvalid() const
Definition: FileOffset.h:27
friend bool operator<=(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:58
Defines the clang::SourceLocation class and associated facilities.
friend bool operator>=(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:54