clang API Documentation
00001 //===----- FileOffset.h - Offset in a file ----------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_EDIT_FILEOFFSET_H 00011 #define LLVM_CLANG_EDIT_FILEOFFSET_H 00012 00013 #include "clang/Basic/SourceLocation.h" 00014 00015 namespace clang { 00016 00017 namespace edit { 00018 00019 class FileOffset { 00020 FileID FID; 00021 unsigned Offs; 00022 public: 00023 FileOffset() : Offs(0) { } 00024 FileOffset(FileID fid, unsigned offs) : FID(fid), Offs(offs) { } 00025 00026 bool isInvalid() const { return FID.isInvalid(); } 00027 00028 FileID getFID() const { return FID; } 00029 unsigned getOffset() const { return Offs; } 00030 00031 FileOffset getWithOffset(unsigned offset) const { 00032 FileOffset NewOffs = *this; 00033 NewOffs.Offs += offset; 00034 return NewOffs; 00035 } 00036 00037 friend bool operator==(FileOffset LHS, FileOffset RHS) { 00038 return LHS.FID == RHS.FID && LHS.Offs == RHS.Offs; 00039 } 00040 friend bool operator!=(FileOffset LHS, FileOffset RHS) { 00041 return !(LHS == RHS); 00042 } 00043 friend bool operator<(FileOffset LHS, FileOffset RHS) { 00044 return std::tie(LHS.FID, LHS.Offs) < std::tie(RHS.FID, RHS.Offs); 00045 } 00046 friend bool operator>(FileOffset LHS, FileOffset RHS) { 00047 return RHS < LHS; 00048 } 00049 friend bool operator>=(FileOffset LHS, FileOffset RHS) { 00050 return !(LHS < RHS); 00051 } 00052 friend bool operator<=(FileOffset LHS, FileOffset RHS) { 00053 return !(RHS < LHS); 00054 } 00055 }; 00056 00057 } 00058 00059 } // end namespace clang 00060 00061 #endif