[C++11] More 'nullptr' conversion or in some cases just using a boolean check instead...
[oota-llvm.git] / include / llvm / Support / YAMLParser.h
index 4180735ed3b73f2def9ed6551009988f89c9d5c5..c5186a5cf65daafc03360249a21dea6f844c1b2e 100644 (file)
@@ -38,7 +38,6 @@
 #ifndef LLVM_SUPPORT_YAMLPARSER_H
 #define LLVM_SUPPORT_YAMLPARSER_H
 
-#include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
@@ -96,8 +95,8 @@ public:
   void printError(Node *N, const Twine &Msg);
 
 private:
-  OwningPtr<Scanner> scanner;
-  OwningPtr<Document> CurrentDoc;
+  std::unique_ptr<Scanner> scanner;
+  std::unique_ptr<Document> CurrentDoc;
 
   friend class Document;
 };
@@ -115,7 +114,7 @@ public:
     NK_Alias
   };
 
-  Node(unsigned int Type, OwningPtr<Document> &, StringRef Anchor,
+  Node(unsigned int Type, std::unique_ptr<Document> &, StringRef Anchor,
        StringRef Tag);
 
   /// @brief Get the value of the anchor attached to this node. If it does not
@@ -156,7 +155,7 @@ public:
   }
 
 protected:
-  OwningPtr<Document> &Doc;
+  std::unique_ptr<Document> &Doc;
   SMRange SourceRange;
 
   void operator delete(void *) throw() {}
@@ -175,9 +174,9 @@ private:
 /// Example:
 ///   !!null null
 class NullNode : public Node {
-  virtual void anchor();
+  void anchor() override;
 public:
-  NullNode(OwningPtr<Document> &D)
+  NullNode(std::unique_ptr<Document> &D)
       : Node(NK_Null, D, StringRef(), StringRef()) {}
 
   static inline bool classof(const Node *N) {
@@ -191,9 +190,9 @@ public:
 /// Example:
 ///   Adena
 class ScalarNode : public Node {
-  virtual void anchor();
+  void anchor() override;
 public:
-  ScalarNode(OwningPtr<Document> &D, StringRef Anchor, StringRef Tag,
+  ScalarNode(std::unique_ptr<Document> &D, StringRef Anchor, StringRef Tag,
              StringRef Val)
       : Node(NK_Scalar, D, Anchor, Tag), Value(Val) {
     SMLoc Start = SMLoc::getFromPointer(Val.begin());
@@ -233,13 +232,11 @@ private:
 /// Example:
 ///   Section: .text
 class KeyValueNode : public Node {
-  virtual void anchor();
+  void anchor() override;
 public:
-  KeyValueNode(OwningPtr<Document> &D)
-    : Node(NK_KeyValue, D, StringRef(), StringRef())
-    , Key(0)
-    , Value(0)
-  {}
+  KeyValueNode(std::unique_ptr<Document> &D)
+    : Node(NK_KeyValue, D, StringRef(), StringRef()), Key(nullptr),
+      Value(nullptr) {}
 
   /// @brief Parse and return the key.
   ///
@@ -255,7 +252,7 @@ public:
   /// @returns The value, or nullptr if failed() == true.
   Node *getValue();
 
-  virtual void skip() LLVM_OVERRIDE {
+  void skip() override {
     getKey()->skip();
     getValue()->skip();
   }
@@ -278,7 +275,7 @@ template <class BaseT, class ValueT>
 class basic_collection_iterator
   : public std::iterator<std::forward_iterator_tag, ValueT> {
 public:
-  basic_collection_iterator() : Base(0) {}
+  basic_collection_iterator() : Base(nullptr) {}
   basic_collection_iterator(BaseT *B) : Base(B) {}
 
   ValueT *operator ->() const {
@@ -308,8 +305,8 @@ public:
     assert(Base && "Attempted to advance iterator past end!");
     Base->increment();
     // Create an end iterator.
-    if (Base->CurrentEntry == 0)
-      Base = 0;
+    if (!Base->CurrentEntry)
+      Base = nullptr;
     return *this;
   }
 
@@ -345,7 +342,7 @@ void skip(CollectionType &C) {
 ///   Name: _main
 ///   Scope: Global
 class MappingNode : public Node {
-  virtual void anchor();
+  void anchor() override;
 public:
   enum MappingType {
     MT_Block,
@@ -353,10 +350,10 @@ public:
     MT_Inline ///< An inline mapping node is used for "[key: value]".
   };
 
-  MappingNode(OwningPtr<Document> &D, StringRef Anchor, StringRef Tag,
+  MappingNode(std::unique_ptr<Document> &D, StringRef Anchor, StringRef Tag,
               MappingType MT)
       : Node(NK_Mapping, D, Anchor, Tag), Type(MT), IsAtBeginning(true),
-        IsAtEnd(false), CurrentEntry(0) {}
+        IsAtEnd(false), CurrentEntry(nullptr) {}
 
   friend class basic_collection_iterator<MappingNode, KeyValueNode>;
   typedef basic_collection_iterator<MappingNode, KeyValueNode> iterator;
@@ -369,7 +366,7 @@ public:
 
   iterator end() { return iterator(); }
 
-  virtual void skip() LLVM_OVERRIDE {
+  void skip() override {
     yaml::skip(*this);
   }
 
@@ -395,7 +392,7 @@ private:
 ///   - Hello
 ///   - World
 class SequenceNode : public Node {
-  virtual void anchor();
+  void anchor() override;
 public:
   enum SequenceType {
     ST_Block,
@@ -410,12 +407,12 @@ public:
     ST_Indentless
   };
 
-  SequenceNode(OwningPtr<Document> &D, StringRef Anchor, StringRef Tag,
+  SequenceNode(std::unique_ptr<Document> &D, StringRef Anchor, StringRef Tag,
                SequenceType ST)
       : Node(NK_Sequence, D, Anchor, Tag), SeqType(ST), IsAtBeginning(true),
         IsAtEnd(false),
         WasPreviousTokenFlowEntry(true), // Start with an imaginary ','.
-        CurrentEntry(0) {}
+        CurrentEntry(nullptr) {}
 
   friend class basic_collection_iterator<SequenceNode, Node>;
   typedef basic_collection_iterator<SequenceNode, Node> iterator;
@@ -430,7 +427,7 @@ public:
 
   iterator end() { return iterator(); }
 
-  virtual void skip() LLVM_OVERRIDE {
+  void skip() override {
     yaml::skip(*this);
   }
 
@@ -451,10 +448,10 @@ private:
 /// Example:
 ///   *AnchorName
 class AliasNode : public Node {
-  virtual void anchor();
+  void anchor() override;
 public:
-  AliasNode(OwningPtr<Document> &D, StringRef Val)
-    : Node(NK_Alias, D, StringRef(), StringRef()), Name(Val) {}
+  AliasNode(std::unique_ptr<Document> &D, StringRef Val)
+      : Node(NK_Alias, D, StringRef(), StringRef()), Name(Val) {}
 
   StringRef getName() const { return Name; }
   Node *getTarget();
@@ -530,8 +527,8 @@ private:
 /// @brief Iterator abstraction for Documents over a Stream.
 class document_iterator {
 public:
-  document_iterator() : Doc(0) {}
-  document_iterator(OwningPtr<Document> &D) : Doc(&D) {}
+  document_iterator() : Doc(nullptr) {}
+  document_iterator(std::unique_ptr<Document> &D) : Doc(&D) {}
 
   bool operator ==(const document_iterator &Other) {
     if (isAtEnd() || Other.isAtEnd())
@@ -544,9 +541,9 @@ public:
   }
 
   document_iterator operator ++() {
-    assert(Doc != 0 && "incrementing iterator past the end.");
+    assert(Doc && "incrementing iterator past the end.");
     if (!(*Doc)->skip()) {
-      Doc->reset(0);
+      Doc->reset(nullptr);
     } else {
       Stream &S = (*Doc)->stream;
       Doc->reset(new Document(S));
@@ -558,16 +555,14 @@ public:
     return *Doc->get();
   }
 
-  OwningPtr<Document> &operator ->() {
-    return *Doc;
-  }
+  std::unique_ptr<Document> &operator->() { return *Doc; }
 
 private:
   bool isAtEnd() const {
     return !Doc || !*Doc;
   }
 
-  OwningPtr<Document> *Doc;
+  std::unique_ptr<Document> *Doc;
 };
 
 }