LLVM  13.0.0git
MemoryBufferRef.h
Go to the documentation of this file.
1 //===- MemoryBufferRef.h - Memory Buffer Reference --------------*- 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 // This file defines the MemoryBuffer interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_SUPPORT_MEMORYBUFFERREF_H
14 #define LLVM_SUPPORT_MEMORYBUFFERREF_H
15 
16 #include "llvm/ADT/StringRef.h"
17 
18 namespace llvm {
19 
20 class MemoryBuffer;
21 
23  StringRef Buffer;
24  StringRef Identifier;
25 
26 public:
27  MemoryBufferRef() = default;
28  MemoryBufferRef(const MemoryBuffer &Buffer);
29  MemoryBufferRef(StringRef Buffer, StringRef Identifier)
30  : Buffer(Buffer), Identifier(Identifier) {}
31 
32  StringRef getBuffer() const { return Buffer; }
33  StringRef getBufferIdentifier() const { return Identifier; }
34 
35  const char *getBufferStart() const { return Buffer.begin(); }
36  const char *getBufferEnd() const { return Buffer.end(); }
37  size_t getBufferSize() const { return Buffer.size(); }
38 
39  /// Check pointer identity (not value) of identifier and data.
40  friend bool operator==(const MemoryBufferRef &LHS,
41  const MemoryBufferRef &RHS) {
42  return LHS.Buffer.begin() == RHS.Buffer.begin() &&
43  LHS.Buffer.end() == RHS.Buffer.end() &&
44  LHS.Identifier.begin() == RHS.Identifier.begin() &&
45  LHS.Identifier.end() == RHS.Identifier.end();
46  }
47 
48  friend bool operator!=(const MemoryBufferRef &LHS,
49  const MemoryBufferRef &RHS) {
50  return !(LHS == RHS);
51  }
52 };
53 
54 } // namespace llvm
55 
56 #endif // LLVM_SUPPORT_MEMORYBUFFERREF_H
llvm::MemoryBufferRef::getBufferStart
const char * getBufferStart() const
Definition: MemoryBufferRef.h:35
llvm
Definition: AllocatorList.h:23
StringRef.h
llvm::MemoryBufferRef::getBufferSize
size_t getBufferSize() const
Definition: MemoryBufferRef.h:37
llvm::MemoryBufferRef::MemoryBufferRef
MemoryBufferRef()=default
llvm::MemoryBufferRef::operator==
friend bool operator==(const MemoryBufferRef &LHS, const MemoryBufferRef &RHS)
Check pointer identity (not value) of identifier and data.
Definition: MemoryBufferRef.h:40
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::MemoryBufferRef::operator!=
friend bool operator!=(const MemoryBufferRef &LHS, const MemoryBufferRef &RHS)
Definition: MemoryBufferRef.h:48
llvm::MemoryBufferRef::getBufferEnd
const char * getBufferEnd() const
Definition: MemoryBufferRef.h:36
llvm::StringRef::end
iterator end() const
Definition: StringRef.h:133
llvm::MemoryBufferRef::MemoryBufferRef
MemoryBufferRef(StringRef Buffer, StringRef Identifier)
Definition: MemoryBufferRef.h:29
llvm::MemoryBufferRef::getBuffer
StringRef getBuffer() const
Definition: MemoryBufferRef.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::MemoryBufferRef::getBufferIdentifier
StringRef getBufferIdentifier() const
Definition: MemoryBufferRef.h:33
llvm::StringRef::begin
iterator begin() const
Definition: StringRef.h:131