//
//===----------------------------------------------------------------------===//
-#ifndef CODEGEN_ASMPRINTER_DIE_H__
-#define CODEGEN_ASMPRINTER_DIE_H__
+#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
+#define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallVector.h"
/// Children DIEs.
///
+ // This can't be a vector<DIE> because pointer validity is requirent for the
+ // Parent pointer and DIEEntry.
+ // It can't be a list<DIE> because some clients need pointer validity before
+ // the object has been added to any child list
+ // (eg: DwarfUnit::constructVariableDIE). These aren't insurmountable, but may
+ // be more convoluted than beneficial.
std::vector<std::unique_ptr<DIE>> Children;
DIE *Parent;
protected:
DIE()
: Offset(0), Size(0), Abbrev((dwarf::Tag)0, dwarf::DW_CHILDREN_no),
- Parent(0) {}
+ Parent(nullptr) {}
public:
explicit DIE(dwarf::Tag Tag)
: Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no),
- Parent(0) {}
+ Parent(nullptr) {}
// Accessors.
DIEAbbrev &getAbbrev() { return Abbrev; }
/// addChild - Add a child to the DIE.
///
- void addChild(DIE *Child) {
+ void addChild(std::unique_ptr<DIE> Child) {
assert(!Child->getParent());
Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
- Children.push_back(std::unique_ptr<DIE>(Child));
Child->Parent = this;
+ Children.push_back(std::move(Child));
}
/// findAttribute - Find a value in the DIE with the attribute given,
///
class DIEString : public DIEValue {
const DIEValue *Access;
- const StringRef Str;
+ StringRef Str;
public:
- DIEString(const DIEValue *Acc, const StringRef S)
+ DIEString(const DIEValue *Acc, StringRef S)
: DIEValue(isString), Access(Acc), Str(S) {}
/// getString - Grab the string out of the object.
/// this class can also be used as a proxy for a debug information entry not
/// yet defined (ie. types.)
class DIEEntry : public DIEValue {
- DIE *const Entry;
+ DIE &Entry;
public:
- explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
- assert(E && "Cannot construct a DIEEntry with a null DIE");
+ explicit DIEEntry(DIE &E) : DIEValue(isEntry), Entry(E) {
}
- DIE *getEntry() const { return Entry; }
+ DIE &getEntry() const { return Entry; }
/// EmitValue - Emit debug information entry offset.
///