summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-06-13 12:49:52 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-06-13 12:49:52 +0000
commit454adf645480245725c74fdbe8840ceff039ef64 (patch)
tree0412a6ae637df95d5eb30d87e35bb26cd220069c /llvm/include
parentd9ad0cbd70426f1b85d37d9059e66b2e5f1f0c8b (diff)
downloadbcm5719-llvm-454adf645480245725c74fdbe8840ceff039ef64.tar.gz
bcm5719-llvm-454adf645480245725c74fdbe8840ceff039ef64.zip
Bring in a BumpPtrStringSaver from lld and simplify the interface.
StringSaver now always saves to a BumpPtrAllocator. The only reason for having the virtual saveImpl is so lld can have a thread safe version. The reason for the distinct BumpPtrStringSaver class is to avoid the virtual destructor. llvm-svn: 239669
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/Support/CommandLine.h13
-rw-r--r--llvm/include/llvm/Support/StringSaver.h42
2 files changed, 45 insertions, 10 deletions
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 1ad8a3bfd93..ed809211ea9 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -33,6 +33,9 @@
namespace llvm {
+class BumpPtrStringSaver;
+class StringSaver;
+
/// cl Namespace - This namespace contains all of the command line option
/// processing machinery. It is intentionally a short name to make qualified
/// usage concise.
@@ -1676,16 +1679,6 @@ StringMap<Option *> &getRegisteredOptions();
// Standalone command line processing utilities.
//
-/// \brief Saves strings in the inheritor's stable storage and returns a stable
-/// raw character pointer.
-class StringSaver {
- virtual void anchor();
-
-public:
- virtual const char *SaveString(const char *Str) = 0;
- virtual ~StringSaver(){}; // Pacify -Wnon-virtual-dtor.
-};
-
/// \brief Tokenizes a command line that can contain escapes and quotes.
//
/// The quoting rules match those used by GCC and other tools that use
diff --git a/llvm/include/llvm/Support/StringSaver.h b/llvm/include/llvm/Support/StringSaver.h
new file mode 100644
index 00000000000..f3853ee9157
--- /dev/null
+++ b/llvm/include/llvm/Support/StringSaver.h
@@ -0,0 +1,42 @@
+//===- llvm/Support/StringSaver.h -------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_STRINGSAVER_H
+#define LLVM_SUPPORT_STRINGSAVER_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Allocator.h"
+
+namespace llvm {
+
+/// \brief Saves strings in the inheritor's stable storage and returns a stable
+/// raw character pointer.
+class StringSaver {
+protected:
+ ~StringSaver() {}
+ virtual const char *saveImpl(StringRef S);
+
+public:
+ StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
+ const char *save(const char *S) { return save(StringRef(S)); }
+ const char *save(StringRef S) { return saveImpl(S); }
+ const char *save(const Twine &S) { return save(StringRef(S.str())); }
+ const char *save(std::string &S) { return save(StringRef(S)); }
+
+private:
+ BumpPtrAllocator &Alloc;
+};
+
+class BumpPtrStringSaver final : public StringSaver {
+public:
+ BumpPtrStringSaver(BumpPtrAllocator &Alloc) : StringSaver(Alloc) {}
+};
+}
+#endif
OpenPOWER on IntegriCloud