summaryrefslogtreecommitdiff
path: root/lib/DebugInfo
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-03-13 08:19:59 +0000
committerAlexey Samsonov <samsonov@google.com>2014-03-13 08:19:59 +0000
commita2b15f5079534ed51b1f0bf9158a1b3a5f4ae688 (patch)
treeb96d9060669dfde06fa88346fad0abbb1d7be7b2 /lib/DebugInfo
parentab849adec4467646aaf25239dc78f47fe5076479 (diff)
downloadllvm-a2b15f5079534ed51b1f0bf9158a1b3a5f4ae688.tar.gz
llvm-a2b15f5079534ed51b1f0bf9158a1b3a5f4ae688.tar.bz2
llvm-a2b15f5079534ed51b1f0bf9158a1b3a5f4ae688.tar.xz
[C++11] DWARF parser: use SmallVector<std::unique_ptr> for parsed units in DWARFContext, and delete custom destructors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203770 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/DebugInfo')
-rw-r--r--lib/DebugInfo/DWARFContext.cpp39
-rw-r--r--lib/DebugInfo/DWARFContext.h12
2 files changed, 20 insertions, 31 deletions
diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp
index 119e3602d0..94935e2568 100644
--- a/lib/DebugInfo/DWARFContext.cpp
+++ b/lib/DebugInfo/DWARFContext.cpp
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
#include "DWARFContext.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Compression.h"
@@ -23,13 +22,6 @@ using namespace object;
typedef DWARFDebugLine::LineTable DWARFLineTable;
-DWARFContext::~DWARFContext() {
- DeleteContainerPointers(CUs);
- DeleteContainerPointers(TUs);
- DeleteContainerPointers(DWOCUs);
- DeleteContainerPointers(DWOTUs);
-}
-
static void dumpPubSection(raw_ostream &OS, StringRef Name, StringRef Data,
bool LittleEndian, bool GnuStyle) {
OS << "\n." << Name << " contents:\n";
@@ -125,7 +117,7 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
savedAddressByteSize = CU->getAddressByteSize();
unsigned stmtOffset =
CU->getCompileUnitDIE()->getAttributeValueAsSectionOffset(
- CU, DW_AT_stmt_list, -1U);
+ CU.get(), DW_AT_stmt_list, -1U);
if (stmtOffset != -1U) {
DataExtractor lineData(getLineSection().Data, isLittleEndian(),
savedAddressByteSize);
@@ -309,7 +301,7 @@ void DWARFContext::parseCompileUnits() {
if (!CU->extract(DIData, &offset)) {
break;
}
- CUs.push_back(CU.release());
+ CUs.push_back(std::move(CU));
offset = CUs.back()->getNextUnitOffset();
}
}
@@ -328,7 +320,7 @@ void DWARFContext::parseTypeUnits() {
&I.second.Relocs, isLittleEndian()));
if (!TU->extract(DIData, &offset))
break;
- TUs.push_back(TU.release());
+ TUs.push_back(std::move(TU));
offset = TUs.back()->getNextUnitOffset();
}
}
@@ -349,7 +341,7 @@ void DWARFContext::parseDWOCompileUnits() {
if (!DWOCU->extract(DIData, &offset)) {
break;
}
- DWOCUs.push_back(DWOCU.release());
+ DWOCUs.push_back(std::move(DWOCU));
offset = DWOCUs.back()->getNextUnitOffset();
}
}
@@ -369,7 +361,7 @@ void DWARFContext::parseDWOTypeUnits() {
isLittleEndian()));
if (!TU->extract(DIData, &offset))
break;
- DWOTUs.push_back(TU.release());
+ DWOTUs.push_back(std::move(TU));
offset = DWOTUs.back()->getNextUnitOffset();
}
}
@@ -377,14 +369,17 @@ void DWARFContext::parseDWOTypeUnits() {
namespace {
struct OffsetComparator {
- bool operator()(const DWARFCompileUnit *LHS,
- const DWARFCompileUnit *RHS) const {
+
+ bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,
+ const std::unique_ptr<DWARFCompileUnit> &RHS) const {
return LHS->getOffset() < RHS->getOffset();
}
- bool operator()(const DWARFCompileUnit *LHS, uint32_t RHS) const {
+ bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,
+ uint32_t RHS) const {
return LHS->getOffset() < RHS;
}
- bool operator()(uint32_t LHS, const DWARFCompileUnit *RHS) const {
+ bool operator()(uint32_t LHS,
+ const std::unique_ptr<DWARFCompileUnit> &RHS) const {
return LHS < RHS->getOffset();
}
};
@@ -393,10 +388,10 @@ namespace {
DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
parseCompileUnits();
- DWARFCompileUnit **CU =
+ std::unique_ptr<DWARFCompileUnit> *CU =
std::lower_bound(CUs.begin(), CUs.end(), Offset, OffsetComparator());
if (CU != CUs.end()) {
- return *CU;
+ return CU->get();
}
return 0;
}
@@ -636,7 +631,7 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
// Make data point to uncompressed section contents and save its contents.
name = name.substr(1);
data = UncompressedSection->getBuffer();
- UncompressedSections.push_back(UncompressedSection.release());
+ UncompressedSections.push_back(std::move(UncompressedSection));
}
StringRef *Section =
@@ -755,8 +750,4 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
}
}
-DWARFContextInMemory::~DWARFContextInMemory() {
- DeleteContainerPointers(UncompressedSections);
-}
-
void DWARFContextInMemory::anchor() { }
diff --git a/lib/DebugInfo/DWARFContext.h b/lib/DebugInfo/DWARFContext.h
index 42d34b18f4..a3bae79273 100644
--- a/lib/DebugInfo/DWARFContext.h
+++ b/lib/DebugInfo/DWARFContext.h
@@ -28,8 +28,8 @@ namespace llvm {
/// information parsing. The actual data is supplied through pure virtual
/// methods that a concrete implementation provides.
class DWARFContext : public DIContext {
- typedef SmallVector<DWARFCompileUnit *, 1> CUVector;
- typedef SmallVector<DWARFTypeUnit *, 1> TUVector;
+ typedef SmallVector<std::unique_ptr<DWARFCompileUnit>, 1> CUVector;
+ typedef SmallVector<std::unique_ptr<DWARFTypeUnit>, 1> TUVector;
CUVector CUs;
TUVector TUs;
@@ -69,7 +69,6 @@ public:
};
DWARFContext() : DIContext(CK_DWARF) {}
- virtual ~DWARFContext();
static bool classof(const DIContext *DICtx) {
return DICtx->getKind() == CK_DWARF;
@@ -131,13 +130,13 @@ public:
/// Get the compile unit at the specified index for this compile unit.
DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
parseCompileUnits();
- return CUs[index];
+ return CUs[index].get();
}
/// Get the compile unit at the specified index for the DWO compile units.
DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
parseDWOCompileUnits();
- return DWOCUs[index];
+ return DWOCUs[index].get();
}
/// Get a pointer to the parsed DebugAbbrev object.
@@ -237,11 +236,10 @@ class DWARFContextInMemory : public DWARFContext {
StringRef RangeDWOSection;
StringRef AddrSection;
- SmallVector<MemoryBuffer*, 4> UncompressedSections;
+ SmallVector<std::unique_ptr<MemoryBuffer>, 4> UncompressedSections;
public:
DWARFContextInMemory(object::ObjectFile *);
- ~DWARFContextInMemory();
bool isLittleEndian() const override { return IsLittleEndian; }
uint8_t getAddressSize() const override { return AddressSize; }
const Section &getInfoSection() override { return InfoSection; }