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() {}
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,
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,
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;
#define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXDIAGNOSTIC_H
#include "clang-c/Index.h"
+#include <memory>
#include <vector>
#include <assert.h>
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();
}
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: