TableGen: unique_ptr-ify RecordKeeper

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216350 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dylan Noblesmith 2014-08-24 19:10:57 +00:00
parent d52b1d08df
commit 7bd541a4dc
4 changed files with 20 additions and 24 deletions

View File

@ -1650,36 +1650,32 @@ struct MultiClass {
}; };
class RecordKeeper { class RecordKeeper {
std::map<std::string, Record*> Classes, Defs; typedef std::map<std::string, std::unique_ptr<Record>> RecordMap;
RecordMap Classes, Defs;
public: public:
~RecordKeeper() { const RecordMap &getClasses() const { return Classes; }
for (std::map<std::string, Record*>::iterator I = Classes.begin(), const RecordMap &getDefs() const { return Defs; }
E = Classes.end(); I != E; ++I)
delete I->second;
for (std::map<std::string, Record*>::iterator I = Defs.begin(),
E = Defs.end(); I != E; ++I)
delete I->second;
}
const std::map<std::string, Record*> &getClasses() const { return Classes; }
const std::map<std::string, Record*> &getDefs() const { return Defs; }
Record *getClass(const std::string &Name) const { Record *getClass(const std::string &Name) const {
std::map<std::string, Record*>::const_iterator I = Classes.find(Name); auto I = Classes.find(Name);
return I == Classes.end() ? nullptr : I->second; return I == Classes.end() ? nullptr : I->second.get();
} }
Record *getDef(const std::string &Name) const { Record *getDef(const std::string &Name) const {
std::map<std::string, Record*>::const_iterator I = Defs.find(Name); auto I = Defs.find(Name);
return I == Defs.end() ? nullptr : I->second; return I == Defs.end() ? nullptr : I->second.get();
} }
void addClass(Record *R) { void addClass(Record *_R) {
bool Ins = Classes.insert(std::make_pair(R->getName(), R)).second; std::unique_ptr<Record> R(_R);
bool Ins = Classes.insert(std::make_pair(R->getName(),
std::move(R))).second;
(void)Ins; (void)Ins;
assert(Ins && "Class already exists"); assert(Ins && "Class already exists");
} }
void addDef(Record *R) { void addDef(Record *_R) {
bool Ins = Defs.insert(std::make_pair(R->getName(), R)).second; std::unique_ptr<Record> R(_R);
bool Ins = Defs.insert(std::make_pair(R->getName(),
std::move(R))).second;
(void)Ins; (void)Ins;
assert(Ins && "Record already exists"); assert(Ins && "Record already exists");
} }

View File

@ -2031,7 +2031,7 @@ RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
std::vector<Record*> Defs; std::vector<Record*> Defs;
for (const auto &D : getDefs()) for (const auto &D : getDefs())
if (D.second->isSubClassOf(Class)) if (D.second->isSubClassOf(Class))
Defs.push_back(D.second); Defs.push_back(D.second.get());
return Defs; return Defs;
} }

View File

@ -75,9 +75,9 @@ void CTagsEmitter::run(raw_ostream &OS) {
// Collect tags. // Collect tags.
Tags.reserve(Classes.size() + Defs.size()); Tags.reserve(Classes.size() + Defs.size());
for (const auto &C : Classes) for (const auto &C : Classes)
Tags.push_back(Tag(C.first, locate(C.second))); Tags.push_back(Tag(C.first, locate(C.second.get())));
for (const auto &D : Defs) for (const auto &D : Defs)
Tags.push_back(Tag(D.first, locate(D.second))); Tags.push_back(Tag(D.first, locate(D.second.get())));
// Emit tags. // Emit tags.
std::sort(Tags.begin(), Tags.end()); std::sort(Tags.begin(), Tags.end());
OS << "!_TAG_FILE_FORMAT\t1\t/original ctags format/\n"; OS << "!_TAG_FILE_FORMAT\t1\t/original ctags format/\n";

View File

@ -280,7 +280,7 @@ void PseudoLoweringEmitter::run(raw_ostream &o) {
for (const auto &D : Records.getDefs()) { for (const auto &D : Records.getDefs()) {
if (D.second->isSubClassOf(ExpansionClass) && if (D.second->isSubClassOf(ExpansionClass) &&
D.second->isSubClassOf(InstructionClass)) D.second->isSubClassOf(InstructionClass))
Insts.push_back(D.second); Insts.push_back(D.second.get());
} }
// Process the pseudo expansion definitions, validating them as we do so. // Process the pseudo expansion definitions, validating them as we do so.