forked from OSchip/llvm-project
Replace std::map<K, V*> with std::map<K, std::unique_ptr<V>> to handle ownership and deletion of the values.
Ideally we would store the MultiClasses by value directly in the maps, but I had some trouble with that before and this at least fixes the leak. llvm-svn: 223997
This commit is contained in:
parent
611a3ef0bc
commit
7adf2bf76a
|
@ -459,7 +459,7 @@ MultiClass *TGParser::ParseMultiClassID() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiClass *Result = MultiClasses[Lex.getCurStrVal()];
|
MultiClass *Result = MultiClasses[Lex.getCurStrVal()].get();
|
||||||
if (!Result)
|
if (!Result)
|
||||||
TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'");
|
TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'");
|
||||||
|
|
||||||
|
@ -2290,11 +2290,14 @@ bool TGParser::ParseMultiClass() {
|
||||||
return TokError("expected identifier after multiclass for name");
|
return TokError("expected identifier after multiclass for name");
|
||||||
std::string Name = Lex.getCurStrVal();
|
std::string Name = Lex.getCurStrVal();
|
||||||
|
|
||||||
if (MultiClasses.count(Name))
|
auto Result =
|
||||||
|
MultiClasses.insert(std::make_pair(Name,
|
||||||
|
llvm::make_unique<MultiClass>(Name, Lex.getLoc(),Records)));
|
||||||
|
|
||||||
|
if (!Result.second)
|
||||||
return TokError("multiclass '" + Name + "' already defined");
|
return TokError("multiclass '" + Name + "' already defined");
|
||||||
|
|
||||||
CurMultiClass = MultiClasses[Name] = new MultiClass(Name,
|
CurMultiClass = Result.first->second.get();
|
||||||
Lex.getLoc(), Records);
|
|
||||||
Lex.Lex(); // Eat the identifier.
|
Lex.Lex(); // Eat the identifier.
|
||||||
|
|
||||||
// If there are template args, parse them.
|
// If there are template args, parse them.
|
||||||
|
@ -2555,7 +2558,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
|
||||||
// To instantiate a multiclass, we need to first get the multiclass, then
|
// To instantiate a multiclass, we need to first get the multiclass, then
|
||||||
// instantiate each def contained in the multiclass with the SubClassRef
|
// instantiate each def contained in the multiclass with the SubClassRef
|
||||||
// template parameters.
|
// template parameters.
|
||||||
MultiClass *MC = MultiClasses[Ref.Rec->getName()];
|
MultiClass *MC = MultiClasses[Ref.Rec->getName()].get();
|
||||||
assert(MC && "Didn't lookup multiclass correctly?");
|
assert(MC && "Didn't lookup multiclass correctly?");
|
||||||
std::vector<Init*> &TemplateVals = Ref.TemplateArgs;
|
std::vector<Init*> &TemplateVals = Ref.TemplateArgs;
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace llvm {
|
||||||
class TGParser {
|
class TGParser {
|
||||||
TGLexer Lex;
|
TGLexer Lex;
|
||||||
std::vector<std::vector<LetRecord> > LetStack;
|
std::vector<std::vector<LetRecord> > LetStack;
|
||||||
std::map<std::string, MultiClass*> MultiClasses;
|
std::map<std::string, std::unique_ptr<MultiClass>> MultiClasses;
|
||||||
|
|
||||||
/// Loops - Keep track of any foreach loops we are within.
|
/// Loops - Keep track of any foreach loops we are within.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue