Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:53

0001 //===- FileOffset.h - Offset in a file --------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_EDIT_FILEOFFSET_H
0010 #define LLVM_CLANG_EDIT_FILEOFFSET_H
0011 
0012 #include "clang/Basic/SourceLocation.h"
0013 #include <tuple>
0014 
0015 namespace clang {
0016 namespace edit {
0017 
0018 class FileOffset {
0019   FileID FID;
0020   unsigned Offs = 0;
0021 
0022 public:
0023   FileOffset() = default;
0024   FileOffset(FileID fid, unsigned offs) : FID(fid), Offs(offs) {}
0025 
0026   bool isInvalid() const { return FID.isInvalid(); }
0027 
0028   FileID getFID() const { return FID; }
0029   unsigned getOffset() const { return Offs; }
0030 
0031   FileOffset getWithOffset(unsigned offset) const {
0032     FileOffset NewOffs = *this;
0033     NewOffs.Offs += offset;
0034     return NewOffs;
0035   }
0036 
0037   friend bool operator==(FileOffset LHS, FileOffset RHS) {
0038     return LHS.FID == RHS.FID && LHS.Offs == RHS.Offs;
0039   }
0040 
0041   friend bool operator!=(FileOffset LHS, FileOffset RHS) {
0042     return !(LHS == RHS);
0043   }
0044 
0045   friend bool operator<(FileOffset LHS, FileOffset RHS) {
0046     return std::tie(LHS.FID, LHS.Offs) < std::tie(RHS.FID, RHS.Offs);
0047   }
0048 
0049   friend bool operator>(FileOffset LHS, FileOffset RHS) {
0050     return RHS < LHS;
0051   }
0052 
0053   friend bool operator>=(FileOffset LHS, FileOffset RHS) {
0054     return !(LHS < RHS);
0055   }
0056 
0057   friend bool operator<=(FileOffset LHS, FileOffset RHS) {
0058     return !(RHS < LHS);
0059   }
0060 };
0061 
0062 } // namespace edit
0063 } // namespace clang
0064 
0065 #endif // LLVM_CLANG_EDIT_FILEOFFSET_H