clang 8.0.0

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
13 #include "clang/Basic/SourceLocation.h"
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
clang::edit::FileOffset::FileOffset
FileOffset(FileID fid, unsigned offs)
Definition: FileOffset.h:25
clang::edit::FileOffset::operator==
friend bool operator==(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:38
clang::edit::FileOffset::operator>
friend bool operator>(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:50
clang::edit::FileOffset::FileOffset
FileOffset()=default
clang::FileID::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:47
clang::edit::FileOffset::getFID
FileID getFID() const
Definition: FileOffset.h:29
clang::edit::FileOffset::operator<
friend bool operator<(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:46
clang::edit::FileOffset::getWithOffset
FileOffset getWithOffset(unsigned offset) const
Definition: FileOffset.h:32
clang::edit::FileOffset::operator!=
friend bool operator!=(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:42
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:40
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::edit::FileOffset::getOffset
unsigned getOffset() const
Definition: FileOffset.h:30
clang::edit::FileOffset::isInvalid
bool isInvalid() const
Definition: FileOffset.h:27
clang::edit::FileOffset::operator<=
friend bool operator<=(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:58
clang::edit::FileOffset
Definition: FileOffset.h:19
SourceLocation.h
Defines the clang::SourceLocation class and associated facilities.
clang::edit::FileOffset::operator>=
friend bool operator>=(FileOffset LHS, FileOffset RHS)
Definition: FileOffset.h:54