From: David Blaikie Date: Fri, 29 Aug 2014 18:43:24 +0000 (+0000) Subject: unique_ptrify the diagnostics in CXDiagnosticSetImpl X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c274d43630e469c4adb988c951ca6047e637cb5;p=clang unique_ptrify the diagnostics in CXDiagnosticSetImpl git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216754 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp index 0d97ebd933..4d646f0cf8 100644 --- a/tools/libclang/CIndexDiagnostic.cpp +++ b/tools/libclang/CIndexDiagnostic.cpp @@ -30,13 +30,11 @@ using namespace clang::cxloc; using namespace clang::cxdiag; using namespace llvm; +CXDiagnosticSetImpl::~CXDiagnosticSetImpl() {} -CXDiagnosticSetImpl::~CXDiagnosticSetImpl() { - for (std::vector::iterator it = Diagnostics.begin(), - et = Diagnostics.end(); - it != et; ++it) { - delete *it; - } +void +CXDiagnosticSetImpl::appendDiagnostic(std::unique_ptr 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(*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(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(Message, L)); } CXDiagnosticSetImpl *CurrentSet; diff --git a/tools/libclang/CIndexDiagnostic.h b/tools/libclang/CIndexDiagnostic.h index a0862ac0dd..4347fb75f4 100644 --- a/tools/libclang/CIndexDiagnostic.h +++ b/tools/libclang/CIndexDiagnostic.h @@ -14,6 +14,7 @@ #define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXDIAGNOSTIC_H #include "clang-c/Index.h" +#include #include #include @@ -24,27 +25,25 @@ class StoredDiagnostic; class CXDiagnosticImpl; class CXDiagnosticSetImpl { - std::vector Diagnostics; + std::vector> 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 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 D) { + ChildDiags.appendDiagnostic(std::move(D)); } private: diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp index 002b8c439e..df8f41440e 100644 --- a/tools/libclang/CXLoadedDiagnostic.cpp +++ b/tools/libclang/CXLoadedDiagnostic.cpp @@ -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;