clang 10.0.0git

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