r216754 - unique_ptrify the diagnostics in CXDiagnosticSetImpl
David Blaikie
dblaikie at gmail.com
Fri Aug 29 11:43:24 PDT 2014
Author: dblaikie
Date: Fri Aug 29 13:43:24 2014
New Revision: 216754
URL: http://llvm.org/viewvc/llvm-project?rev=216754&view=rev
Log:
unique_ptrify the diagnostics in CXDiagnosticSetImpl
Modified:
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
cfe/trunk/tools/libclang/CIndexDiagnostic.h
cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=216754&r1=216753&r2=216754&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Fri Aug 29 13:43:24 2014
@@ -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;
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.h?rev=216754&r1=216753&r2=216754&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.h (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.h Fri Aug 29 13:43:24 2014
@@ -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:
Modified: cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp?rev=216754&r1=216753&r2=216754&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp Fri Aug 29 13:43:24 2014
@@ -567,7 +567,7 @@ LoadResult DiagLoader::readDiagnosticBlo
continue;
}
case Read_BlockEnd:
- Diags.appendDiagnostic(D.release());
+ Diags.appendDiagnostic(std::move(D));
return Success;
case Read_Record:
break;
More information about the cfe-commits
mailing list