mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223997 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0aac0703f8
commit
50083146f0
@ -459,7 +459,7 @@ MultiClass *TGParser::ParseMultiClassID() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MultiClass *Result = MultiClasses[Lex.getCurStrVal()];
|
||||
MultiClass *Result = MultiClasses[Lex.getCurStrVal()].get();
|
||||
if (!Result)
|
||||
TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'");
|
||||
|
||||
@ -2290,11 +2290,14 @@ bool TGParser::ParseMultiClass() {
|
||||
return TokError("expected identifier after multiclass for name");
|
||||
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");
|
||||
|
||||
CurMultiClass = MultiClasses[Name] = new MultiClass(Name,
|
||||
Lex.getLoc(), Records);
|
||||
CurMultiClass = Result.first->second.get();
|
||||
Lex.Lex(); // Eat the identifier.
|
||||
|
||||
// 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
|
||||
// instantiate each def contained in the multiclass with the SubClassRef
|
||||
// template parameters.
|
||||
MultiClass *MC = MultiClasses[Ref.Rec->getName()];
|
||||
MultiClass *MC = MultiClasses[Ref.Rec->getName()].get();
|
||||
assert(MC && "Didn't lookup multiclass correctly?");
|
||||
std::vector<Init*> &TemplateVals = Ref.TemplateArgs;
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace llvm {
|
||||
class TGParser {
|
||||
TGLexer Lex;
|
||||
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.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user