diff options
author | dim <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-04-14 14:01:31 +0000 |
commit | 50b73317314e889cf39c7b1d6cbf419fa7502f22 (patch) | |
tree | be1815eb79b42ff482a8562b13c2dcbf0c5dcbee /include/clang/Edit/FileOffset.h | |
parent | dc04cb328508e61aad809d9b53b12f9799a00e7d (diff) | |
download | FreeBSD-src-50b73317314e889cf39c7b1d6cbf419fa7502f22.zip FreeBSD-src-50b73317314e889cf39c7b1d6cbf419fa7502f22.tar.gz |
Vendor import of clang trunk r154661:
http://llvm.org/svn/llvm-project/cfe/trunk@r154661
Diffstat (limited to 'include/clang/Edit/FileOffset.h')
-rw-r--r-- | include/clang/Edit/FileOffset.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/include/clang/Edit/FileOffset.h b/include/clang/Edit/FileOffset.h new file mode 100644 index 0000000..675ad18 --- /dev/null +++ b/include/clang/Edit/FileOffset.h @@ -0,0 +1,65 @@ +//===----- FileOffset.h - Offset in a file ----------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_EDIT_FILEOFFSET_H +#define LLVM_CLANG_EDIT_FILEOFFSET_H + +#include "clang/Basic/SourceLocation.h" + +namespace clang { + +namespace edit { + +class FileOffset { + FileID FID; + unsigned Offs; +public: + FileOffset() : Offs(0) { } + FileOffset(FileID fid, unsigned offs) : FID(fid), Offs(offs) { } + + bool isInvalid() const { return FID.isInvalid(); } + + FileID getFID() const { return FID; } + unsigned getOffset() const { return Offs; } + + FileOffset getWithOffset(unsigned offset) const { + FileOffset NewOffs = *this; + NewOffs.Offs += offset; + return NewOffs; + } + + friend bool operator==(FileOffset LHS, FileOffset RHS) { + return LHS.FID == RHS.FID && LHS.Offs == RHS.Offs; + } + friend bool operator!=(FileOffset LHS, FileOffset RHS) { + return !(LHS == RHS); + } + friend bool operator<(FileOffset LHS, FileOffset RHS) { + if (LHS.FID != RHS.FID) + return LHS.FID < RHS.FID; + return LHS.Offs < RHS.Offs; + } + friend bool operator>(FileOffset LHS, FileOffset RHS) { + if (LHS.FID != RHS.FID) + return LHS.FID > RHS.FID; + return LHS.Offs > RHS.Offs; + } + friend bool operator>=(FileOffset LHS, FileOffset RHS) { + return LHS > RHS || LHS == RHS; + } + friend bool operator<=(FileOffset LHS, FileOffset RHS) { + return LHS < RHS || LHS == RHS; + } +}; + +} + +} // end namespace clang + +#endif |