1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00
llvm-mirror/include/llvm/Support/MemoryBufferRef.h
Duncan P. N. Exon Smith b7c96281d2 Support: Add operator== for MemoryBufferRef and split out MemoryBufferRef.h
As preparation for changing `LineIterator` to work with `MemoryBufferRef`:

- Add an `operator==` that uses buffer pointer identity to ensure two buffers
  are equivalent.
- Split out `MemoryBufferRef.h`, to avoid polluting `LineIterator.h` includers
  with everything from `MemoryBuffer.h`. This also means moving the
  `MemoryBuffer` constructor to a source file.

Differential Revision: https://reviews.llvm.org/D89279
2020-10-13 16:42:24 -04:00

57 lines
1.8 KiB
C++

//===- MemoryBufferRef.h - Memory Buffer Reference --------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the MemoryBuffer interface.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_SUPPORT_MEMORYBUFFERREF_H
#define LLVM_SUPPORT_MEMORYBUFFERREF_H
#include "llvm/ADT/StringRef.h"
namespace llvm {
class MemoryBuffer;
class MemoryBufferRef {
StringRef Buffer;
StringRef Identifier;
public:
MemoryBufferRef() = default;
MemoryBufferRef(const MemoryBuffer &Buffer);
MemoryBufferRef(StringRef Buffer, StringRef Identifier)
: Buffer(Buffer), Identifier(Identifier) {}
StringRef getBuffer() const { return Buffer; }
StringRef getBufferIdentifier() const { return Identifier; }
const char *getBufferStart() const { return Buffer.begin(); }
const char *getBufferEnd() const { return Buffer.end(); }
size_t getBufferSize() const { return Buffer.size(); }
/// Check pointer identity (not value) of identifier and data.
friend bool operator==(const MemoryBufferRef &LHS,
const MemoryBufferRef &RHS) {
return LHS.Buffer.begin() == RHS.Buffer.begin() &&
LHS.Buffer.end() == RHS.Buffer.end() &&
LHS.Identifier.begin() == RHS.Identifier.begin() &&
LHS.Identifier.end() == RHS.Identifier.end();
}
friend bool operator!=(const MemoryBufferRef &LHS,
const MemoryBufferRef &RHS) {
return !(LHS == RHS);
}
};
} // namespace llvm
#endif // LLVM_SUPPORT_MEMORYBUFFERREF_H