]> granicus.if.org Git - clang/commitdiff
unique_ptrify the diagnostics in CXDiagnosticSetImpl
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 29 Aug 2014 18:43:24 +0000 (18:43 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 29 Aug 2014 18:43:24 +0000 (18:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216754 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndexDiagnostic.cpp
tools/libclang/CIndexDiagnostic.h
tools/libclang/CXLoadedDiagnostic.cpp

index 0d97ebd9335bef5be4271de81ecba388d4cf4446..4d646f0cf828131f704b7b3dff634d04516c7c80 100644 (file)
@@ -30,13 +30,11 @@ using namespace clang::cxloc;
 using namespace clang::cxdiag;
 using namespace llvm;
 
+CXDiagnosticSetImpl::~CXDiagnosticSetImpl() {}
 
-CXDiagnosticSetImpl::~CXDiagnosticSetImpl() {
-  for (std::vector<CXDiagnosticImpl *>::iterator it = Diagnostics.begin(),
-       et = Diagnostics.end();
-       it != et; ++it) {
-    delete *it;
-  }
+void
+CXDiagnosticSetImpl::appendDiagnostic(std::unique_ptr<CXDiagnosticImpl> D) {
+  Diagnostics.push_back(std::move(D));
 }
 
 CXDiagnosticImpl::~CXDiagnosticImpl() {}
@@ -105,12 +103,13 @@ public:
     
     if (Level != DiagnosticsEngine::Note)
       CurrentSet = MainSet;
-    
-    CXStoredDiagnostic *CD = new CXStoredDiagnostic(*SD, LangOpts);
-    CurrentSet->appendDiagnostic(CD);
-    
+
+    auto Owner = llvm::make_unique<CXStoredDiagnostic>(*SD, LangOpts);
+    CXStoredDiagnostic &CD = *Owner;
+    CurrentSet->appendDiagnostic(std::move(Owner));
+
     if (Level != DiagnosticsEngine::Note)
-      CurrentSet = &CD->getChildDiagnostics();
+      CurrentSet = &CD.getChildDiagnostics();
   }
 
   void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
@@ -127,8 +126,8 @@ public:
       L = translateSourceLocation(*SM, LangOpts, Loc);
     else
       L = clang_getNullLocation();
-    CXDiagnosticImpl *CD = new CXDiagnosticCustomNoteImpl(Message, L);
-    CurrentSet->appendDiagnostic(CD);
+    CurrentSet->appendDiagnostic(
+        llvm::make_unique<CXDiagnosticCustomNoteImpl>(Message, L));
   }
 
   void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
@@ -149,8 +148,8 @@ public:
       L = translateSourceLocation(*SM, LangOpts, Loc);
     else
       L = clang_getNullLocation();
-    CurrentSet->appendDiagnostic(new CXDiagnosticCustomNoteImpl(Message,
-                                                                L));
+    CurrentSet->appendDiagnostic(
+        llvm::make_unique<CXDiagnosticCustomNoteImpl>(Message, L));
   }
 
   CXDiagnosticSetImpl *CurrentSet;
index a0862ac0dde8db2eae73e1033b7926feec2c818a..4347fb75f4a5b32ca54350f884e39ae39f68fccb 100644 (file)
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXDIAGNOSTIC_H
 
 #include "clang-c/Index.h"
+#include <memory>
 #include <vector>
 #include <assert.h>
 
@@ -24,27 +25,25 @@ class StoredDiagnostic;
 class CXDiagnosticImpl;
   
 class CXDiagnosticSetImpl {
-  std::vector<CXDiagnosticImpl *> Diagnostics;
+  std::vector<std::unique_ptr<CXDiagnosticImpl>> Diagnostics;
   const bool IsExternallyManaged;
 public:
   CXDiagnosticSetImpl(bool isManaged = false)
     : IsExternallyManaged(isManaged) {}
 
   virtual ~CXDiagnosticSetImpl();
-  
+
   size_t getNumDiagnostics() const {
     return Diagnostics.size();
   }
   
   CXDiagnosticImpl *getDiagnostic(unsigned i) const {
     assert(i < getNumDiagnostics());
-    return Diagnostics[i];
+    return Diagnostics[i].get();
   }
-  
-  void appendDiagnostic(CXDiagnosticImpl *D) {
-    Diagnostics.push_back(D);
-  }
-  
+
+  void appendDiagnostic(std::unique_ptr<CXDiagnosticImpl> D);
+
   bool empty() const {
     return Diagnostics.empty();
   }
@@ -99,9 +98,9 @@ public:
 protected:
   CXDiagnosticImpl(Kind k) : K(k) {}
   CXDiagnosticSetImpl ChildDiags;
-  
-  void append(CXDiagnosticImpl *D) {
-    ChildDiags.appendDiagnostic(D);
+
+  void append(std::unique_ptr<CXDiagnosticImpl> D) {
+    ChildDiags.appendDiagnostic(std::move(D));
   }
   
 private:
index 002b8c439eb2ddf892335333828439fa7f4d29f6..df8f41440ee0addeaf76c8b291e22df238bd9fbd 100644 (file)
@@ -567,7 +567,7 @@ LoadResult DiagLoader::readDiagnosticBlock(llvm::BitstreamCursor &Stream,
         continue;
       }
       case Read_BlockEnd:
-        Diags.appendDiagnostic(D.release());
+        Diags.appendDiagnostic(std::move(D));
         return Success;
       case Read_Record:
         break;