]> granicus.if.org Git - llvm/commitdiff
Use StringRef for MemoryBuffer identifier API (NFC)
authorMehdi Amini <mehdi.amini@apple.com>
Sat, 1 Oct 2016 16:38:28 +0000 (16:38 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Sat, 1 Oct 2016 16:38:28 +0000 (16:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283043 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/ObjectMemoryBuffer.h
include/llvm/Support/MemoryBuffer.h
lib/Support/MemoryBuffer.cpp
lib/Support/SourceMgr.cpp
utils/TableGen/CTagsEmitter.cpp

index b07561152ec061eed3e175369aa462c97a59e0db..0f00ad006a7dda8dc4191f852ec5f140e5d02e88 100644 (file)
@@ -49,7 +49,7 @@ public:
     init(this->SV.begin(), this->SV.end(), false);
   }
 
-  const char* getBufferIdentifier() const override { return BufferName.c_str(); }
+  StringRef getBufferIdentifier() const override { return BufferName; }
 
   BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
 
index 73d643537a6f2b5b1399856d9ef4f9b8e7ee8bed..70d91bdc26ad1bbc60cb356ac023d6116969cb45 100644 (file)
@@ -56,9 +56,7 @@ public:
 
   /// Return an identifier for this buffer, typically the filename it was read
   /// from.
-  virtual const char *getBufferIdentifier() const {
-    return "Unknown buffer";
-  }
+  virtual StringRef getBufferIdentifier() const { return "Unknown buffer"; }
 
   /// Open the specified file as a MemoryBuffer, returning a new MemoryBuffer
   /// if successful, otherwise returning null. If FileSize is specified, this
index b935cbf1ae7a988018ba9f79987db0d8f1cab5d9..689343206c5af6ab7e415749114e1df062dc4df6 100644 (file)
@@ -90,9 +90,9 @@ public:
   /// tail-allocated data.
   void operator delete(void *p) { ::operator delete(p); }
 
-  const char *getBufferIdentifier() const override {
-     // The name is stored after the class itself.
-    return reinterpret_cast<const char*>(this + 1);
+  StringRef getBufferIdentifier() const override {
+    // The name is stored after the class itself.
+    return StringRef(reinterpret_cast<const char *>(this + 1));
   }
 
   BufferKind getBufferKind() const override {
@@ -221,9 +221,9 @@ public:
   /// tail-allocated data.
   void operator delete(void *p) { ::operator delete(p); }
 
-  const char *getBufferIdentifier() const override {
+  StringRef getBufferIdentifier() const override {
     // The name is stored after the class itself.
-    return reinterpret_cast<const char *>(this + 1);
+    return StringRef(reinterpret_cast<const char *>(this + 1));
   }
 
   BufferKind getBufferKind() const override {
index b2f87d648458a4044a51c6429af5553833428617..4cb9b2ff2cdaea7f459a94025e927f56cf206f80 100644 (file)
@@ -142,7 +142,7 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
   // location to pull out the source line.
   SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges;
   std::pair<unsigned, unsigned> LineAndCol;
-  const char *BufferID = "<unknown>";
+  StringRef BufferID = "<unknown>";
   std::string LineStr;
   
   if (Loc.isValid()) {
index 35f4ad6dd5bf11188da78d304e4aadf452891017..5213cd90446283e3985c784d61f92e3477074d60 100644 (file)
@@ -37,7 +37,7 @@ public:
   void emit(raw_ostream &OS) const {
     const MemoryBuffer *CurMB =
         SrcMgr.getMemoryBuffer(SrcMgr.FindBufferContainingLoc(Loc));
-    const char *BufferName = CurMB->getBufferIdentifier();
+    auto BufferName = CurMB->getBufferIdentifier();
     std::pair<unsigned, unsigned> LineAndColumn = SrcMgr.getLineAndColumn(Loc);
     OS << *Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n";
   }